Skip to content

Commit

Permalink
Restored AttributeUsage projection (#809)
Browse files Browse the repository at this point in the history
* Restored AttributeUsage projection

* Restored AllowMultiple attribute arg as well

* Add test for multiple allowed attributes
  • Loading branch information
Scottj1s authored Apr 19, 2021
1 parent 039332d commit 5695e66
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/Tests/UnitTest/WinUITest.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using WinRT;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace UnitTest
{
Expand All @@ -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()
{
Expand Down
16 changes: 13 additions & 3 deletions src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ remove => %.% -= value;
void write_custom_attributes(writer& w, std::pair<CustomAttribute, CustomAttribute> const& custom_attributes, bool enable_platform_attrib)
{
std::map<std::string, std::vector<std::string>> attributes;
bool allow_multiple = false;
for (auto&& attribute : custom_attributes)
{
auto [attribute_namespace, attribute_name] = attribute.TypeNamespaceAndName();
Expand All @@ -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"));
}

Expand Down

0 comments on commit 5695e66

Please sign in to comment.