Skip to content

Commit

Permalink
Add public option to embedded support for enums (#1187)
Browse files Browse the repository at this point in the history
* Add option to generate enums as public with embedded option
  • Loading branch information
j0shuams authored May 11, 2022
1 parent c9c6e40 commit 9b8764e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions nuget/Microsoft.Windows.CsWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<CsWinRTInternalProjection Condition="'$(CsWinRTPrivateProjection)' == 'true'">-internal</CsWinRTInternalProjection>
<CsWinRTEmbeddedProjection Condition="'$(CsWinRTEmbedded)' == 'true'">-embedded</CsWinRTEmbeddedProjection>
<CsWinRTEmbeddedEnums Condition="'$(CsWinRTEmbeddedPublicEnums)' == 'true'">-public_enums</CsWinRTEmbeddedEnums>
<CsWinRTExeTFM Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) == 5">net5.0</CsWinRTExeTFM>
<CsWinRTExeTFM Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) > 5">net6.0</CsWinRTExeTFM>
<CsWinRTExeTFM Condition="'$(CsWinRTExeTFM)' == ''">netstandard2.0</CsWinRTExeTFM>
Expand All @@ -153,6 +154,7 @@ $(CsWinRTWindowsMetadataInput)
$(CsWinRTFilters)
$(CsWinRTIncludeWinRTInterop)
$(CsWinRTEmbeddedProjection)
$(CsWinRTEmbeddedEnums)
</CsWinRTParams>

<CsWinRTPrivateParams Condition="'$(CsWinRTPrivateParams)' == ''">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<CsWinRTWindowsMetadata>10.0.19041.0</CsWinRTWindowsMetadata>
<SimulateCsWinRTNugetReference>true</SimulateCsWinRTNugetReference>
<CsWinRTGenerateProjection>true</CsWinRTGenerateProjection>
<!-- Will expose enums as public in the projection
<CsWinRTEmbeddedPublicEnums>true</CsWinRTEmbeddedPublicEnums> -->
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7024,7 +7024,7 @@ global::WinRT.ComWrappersSupport.FindObject<%>(%).Invoke(%)
)",
bind<write_winrt_attribute>(type),
bind<write_type_custom_attributes>(type, true),
internal_accessibility(),
(settings.internal || settings.embedded) ? (settings.public_enums ? "public" : "internal") : "public",
bind<write_type_name>(type, typedef_name_type::Projected, false), enum_underlying_type);
{
for (auto&& field : type.FieldList())
Expand Down
2 changes: 2 additions & 0 deletions src/cswinrt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace cswinrt
{ "verbose", 0, 0, {}, "Show detailed progress information" },
{ "internal", 0, 0, {}, "Generates a private projection."},
{ "embedded", 0, 0, {}, "Generates an embedded projection."},
{ "public_enums", 0, 0, {}, "Used with embedded option to generate enums as public"},
{ "help", 0, option::no_max, {}, "Show detailed help" },
{ "?", 0, option::no_max, {}, {} },
};
Expand Down Expand Up @@ -97,6 +98,7 @@ Where <spec> is one or more of:
settings.component = args.exists("component");
settings.internal = args.exists("internal");
settings.embedded = args.exists("embedded");
settings.public_enums = args.exists("public_enums");
settings.input = args.files("input", database::is_database);

for (auto && include : args.values("include"))
Expand Down
1 change: 1 addition & 0 deletions src/cswinrt/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace cswinrt
bool component{};
bool internal{};
bool embedded{};
bool public_enums{};
};

extern settings_type settings;
Expand Down

0 comments on commit 9b8764e

Please sign in to comment.