File tree Expand file tree Collapse file tree 3 files changed +54
-5
lines changed
Expand file tree Collapse file tree 3 files changed +54
-5
lines changed Original file line number Diff line number Diff line change @@ -115,15 +115,26 @@ namespace winrt::impl
115115
116116 bool IndexOf (Windows::Foundation::IInspectable const & value, uint32_t & index) const
117117 {
118- try
118+ if constexpr (is_com_interface_v<T>)
119119 {
120- return IndexOf (unbox_value<T>(value), index);
120+ if (!value)
121+ {
122+ return base_type::IndexOf (nullptr , index);
123+ }
124+ else if (auto as = value.try_as <T>())
125+ {
126+ return base_type::IndexOf (as, index);
127+ }
121128 }
122- catch (hresult_no_interface const &)
129+ else
123130 {
124- index = 0 ;
125- return false ;
131+ if (auto as = value.try_as <T>())
132+ {
133+ return base_type::IndexOf (as.value (), index);
134+ }
126135 }
136+
137+ return false ;
127138 }
128139
129140 using base_type::GetMany;
Original file line number Diff line number Diff line change 1+ #include " pch.h"
2+
3+ using namespace winrt ;
4+ using namespace Windows ::Foundation;
5+ using namespace Windows ::Foundation::Collections;
6+
7+ TEST_CASE (" observable_index_of" )
8+ {
9+ {
10+ auto v = single_threaded_observable_vector<int >().as <IVector<IInspectable>>();
11+ v.Append (box_value (123 ));
12+ uint32_t index = 0 ;
13+ REQUIRE (v.IndexOf (box_value (123 ), index));
14+ REQUIRE (!v.IndexOf (nullptr , index));
15+ REQUIRE (!v.IndexOf (box_value (456 ), index));
16+ REQUIRE (!v.IndexOf (Uri (L" http://kennykerr.ca" ), index));
17+ }
18+ {
19+ auto value = Uri (L" http://kennykerr.ca" );
20+
21+ auto v = single_threaded_observable_vector<IStringable>().as <IVector<IInspectable>>();
22+ v.Append (value);
23+ uint32_t index = 0 ;
24+ REQUIRE (v.IndexOf (value, index));
25+ REQUIRE (!v.IndexOf (nullptr , index));
26+ REQUIRE (!v.IndexOf (box_value (456 ), index));
27+ REQUIRE (!v.IndexOf (Uri (L" http://kennykerr.ca" ), index));
28+ }
29+ {
30+ auto v = single_threaded_observable_vector<IStringable>().as <IVector<IInspectable>>();
31+ v.Append (nullptr );
32+ uint32_t index = 0 ;
33+ REQUIRE (v.IndexOf (nullptr , index));
34+ REQUIRE (!v.IndexOf (box_value (456 ), index));
35+ REQUIRE (!v.IndexOf (Uri (L" http://kennykerr.ca" ), index));
36+ }
37+ }
Original file line number Diff line number Diff line change 417417 <ClCompile Include =" notify_awaiter.cpp" />
418418 <ClCompile Include =" no_make_detection.cpp" />
419419 <ClCompile Include =" numerics.cpp" />
420+ <ClCompile Include =" observable_index_of.cpp" />
420421 <ClCompile Include =" out_params.cpp" />
421422 <ClCompile Include =" out_params_abi.cpp" />
422423 <ClCompile Include =" out_params_bad.cpp" />
You can’t perform that action at this time.
0 commit comments