diff --git a/src/Tests/UnitTest/WinUITest.net5.cs b/src/Tests/UnitTest/WinUITest.net5.cs index 7abd9d2c0..6329cf614 100644 --- a/src/Tests/UnitTest/WinUITest.net5.cs +++ b/src/Tests/UnitTest/WinUITest.net5.cs @@ -8,6 +8,8 @@ using WinRT; using Windows.Foundation; using Windows.Foundation.Collections; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; namespace UnitTest { @@ -20,8 +22,13 @@ public TestWinUI() public class App : Microsoft.UI.Xaml.Application { - } - + } + + // Compile time test to ensure multiple allowed attributes + [TemplatePart(Name = "PartButton", Type = typeof(Button))] + [TemplatePart(Name = "PartGrid", Type = typeof(Grid))] + public class TestAllowMultipleAttributes { }; + [Fact] public void TestApp() { diff --git a/src/cswinrt/code_writers.h b/src/cswinrt/code_writers.h index 8344b6598..47abf26f6 100644 --- a/src/cswinrt/code_writers.h +++ b/src/cswinrt/code_writers.h @@ -1407,6 +1407,7 @@ remove => %.% -= value; void write_custom_attributes(writer& w, std::pair const& custom_attributes, bool enable_platform_attrib) { std::map> attributes; + bool allow_multiple = false; for (auto&& attribute : custom_attributes) { auto [attribute_namespace, attribute_name] = attribute.TypeNamespaceAndName(); @@ -1426,13 +1427,22 @@ remove => %.% -= value; attributes["global::System.Runtime.Versioning.SupportedOSPlatform"].push_back(platform); } } - // Skip metadata attributes - if (attribute_namespace == "Windows.Foundation.Metadata" && attribute_name != "DefaultOverload" && attribute_name != "Overload") continue; + // Skip metadata attributes without a projection + if (attribute_namespace == "Windows.Foundation.Metadata") + { + if (attribute_name == "AllowMultiple") + { + allow_multiple = true; + } + if (attribute_name != "DefaultOverload" && attribute_name != "Overload" && attribute_name != "AttributeUsage") + { + continue; + } + } attributes[attribute_full] = std::move(params); } if (auto&& usage = attributes.find("AttributeUsage"); usage != attributes.end()) { - bool allow_multiple = attributes.find("Windows.Foundation.Metadata.AllowMultiple") != attributes.end(); usage->second.push_back(w.write_temp("AllowMultiple = %", allow_multiple ? "true" : "false")); }