Skip to content

Commit abcdc75

Browse files
authored
Add to_hstring overload for IStringable (#1271)
1 parent 4e674c7 commit abcdc75

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

cppwinrt/code_writers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3253,6 +3253,7 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable<T, D, %>
32533253
w.write(strings::base_reference_produce);
32543254
w.write(strings::base_deferral);
32553255
w.write(strings::base_coroutine_foundation);
3256+
w.write(strings::base_stringable_to_hstring);
32563257
w.write(strings::base_stringable_format);
32573258
w.write(strings::base_stringable_streams);
32583259
}

cppwinrt/cppwinrt.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<ClInclude Include="..\strings\base_string.h" />
8282
<ClInclude Include="..\strings\base_stringable_format.h" />
8383
<ClInclude Include="..\strings\base_stringable_streams.h" />
84+
<ClInclude Include="..\strings\base_stringable_to_hstring.h" />
8485
<ClInclude Include="..\strings\base_string_input.h" />
8586
<ClInclude Include="..\strings\base_string_operators.h" />
8687
<ClInclude Include="..\strings\base_stringable_format_1.h" />

cppwinrt/cppwinrt.vcxproj.filters

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
<ClInclude Include="..\strings\base_stringable_format.h">
170170
<Filter>strings</Filter>
171171
</ClInclude>
172-
<ClInclude Include="..\strings\base_stringable_streams.h">
172+
<ClInclude Include="..\strings\base_stringable_streams.h">
173173
<Filter>strings</Filter>
174174
</ClInclude>
175175
<ClInclude Include="..\strings\base_xaml_component_connector.h">
@@ -184,6 +184,9 @@
184184
<ClInclude Include="..\strings\base_xaml_component_connector_winui.h">
185185
<Filter>strings</Filter>
186186
</ClInclude>
187+
<ClInclude Include="..\strings\base_stringable_to_hstring.h">
188+
<Filter>strings</Filter>
189+
</ClInclude>
187190
</ItemGroup>
188191
<ItemGroup>
189192
<ResourceCompile Include="$(OutDir)version.rc" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
WINRT_EXPORT namespace winrt
3+
{
4+
inline hstring to_hstring(Windows::Foundation::IStringable const& stringable)
5+
{
6+
return stringable.ToString();
7+
}
8+
}

test/old_tests/UnitTests/to_hstring.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
using namespace winrt;
66

7+
struct stringable : winrt::implements<stringable, winrt::Windows::Foundation::IStringable>
8+
{
9+
winrt::hstring ToString()
10+
{
11+
return L"a stringable object";
12+
}
13+
};
14+
715
namespace
816
{
917
void test_cases()
@@ -82,6 +90,10 @@ namespace
8290
hstring const c = to_hstring(b);
8391
REQUIRE(a == c);
8492
}
93+
{
94+
auto const obj = make<stringable>();
95+
REQUIRE(to_hstring(obj) == obj.ToString());
96+
}
8597
}
8698
}
8799

0 commit comments

Comments
 (0)