Skip to content

Commit

Permalink
Fix an edge case with XAML enum types
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jan 3, 2025
1 parent e3e90d7 commit e73eb24
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,12 @@ void HandleSetAccessor(IPropertySymbol propertySymbol, PropertyFlags propertyFla
// We have found a valid constant. If it's an enum type, we have a couple special cases to handle.
if (conversionOperation.Operand.Type is { TypeKind: TypeKind.Enum } operandType)
{
// As an optimization, we check whether the constant was the value
// As an optimization, we check whether the constant was the default value (not other enum member)
// of some projected built-in WinRT enum type (ie. not any user-defined enum type). If that is the
// case, the XAML infrastructure can default that values automatically, meaning we can skip the
// overhead of instantiating a 'PropertyMetadata' instance in code, and marshalling default value.
if (operandType.IsContainedInNamespace(WellKnownTypeNames.XamlNamespace(useWindowsUIXaml)))
// We also need to exclude scenarios where the property is actually nullable, but we're assigning a value.
if (operandType.IsContainedInNamespace(WellKnownTypeNames.XamlNamespace(useWindowsUIXaml)) && !isNullableValueType)
{
// Before actually enabling the optimization, validate that the default value is actually
// the same as the default value of the enum (ie. the value of its first declared field).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2443,8 +2443,8 @@ public abstract partial class KeyFrame<TValue, TKeyFrame> : DependencyObject
[DataRow("Visibility", "object", "new PropertyMetadata(default(Visibility))", "(PropertyType = typeof(object))")]
[DataRow("Visibility?", "Visibility?", "null", "")]
[DataRow("Visibility?", "Visibility?", "new PropertyMetadata(null)", "")]
//[DataRow("Visibility?", "Visibility?", "new PropertyMetadata(default(Visibility))", "(DefaultValue = Visibility.Visible)")]
//[DataRow("Visibility?", "Visibility?", "new PropertyMetadata(Visibility.Visible)", "(DefaultValue = Visibility.Visible)")]
[DataRow("Visibility?", "Visibility?", "new PropertyMetadata(default(Visibility))", "(DefaultValue = Visibility.Visible)")]
[DataRow("Visibility?", "Visibility?", "new PropertyMetadata(Visibility.Visible)", "(DefaultValue = Visibility.Visible)")]
[DataRow("Visibility?", "Visibility?", "new PropertyMetadata(Visibility.Collapsed)", "(DefaultValue = Visibility.Collapsed)")]
[DataRow("Visibility?", "object", "null", "(PropertyType = typeof(object))")]
[DataRow("Visibility?", "object", "new PropertyMetadata(null)", "(PropertyType = typeof(object))")]
Expand All @@ -2459,7 +2459,7 @@ public abstract partial class KeyFrame<TValue, TKeyFrame> : DependencyObject
[DataRow("MyEnum", "object", "new PropertyMetadata(default(MyEnum))", "(PropertyType = typeof(object))")]
[DataRow("MyEnum?", "MyEnum?", "null", "")]
[DataRow("MyEnum?", "MyEnum?", "new PropertyMetadata(null)", "")]
//[DataRow("MyEnum?", "MyEnum?", "new PropertyMetadata(default(MyEnum))", "(DefaultValue = MyEnum.A)")]
[DataRow("MyEnum?", "MyEnum?", "new PropertyMetadata(default(MyEnum))", "(DefaultValue = MyEnum.A)")]
[DataRow("MyEnum?", "MyEnum?", "new PropertyMetadata(MyEnum.A)", "(DefaultValue = MyEnum.A)")]
[DataRow("MyEnum?", "MyEnum?", "new PropertyMetadata(MyEnum.B)", "(DefaultValue = MyEnum.B)")]
[DataRow("MyEnum?", "object", "null", "(PropertyType = typeof(object))")]
Expand Down

0 comments on commit e73eb24

Please sign in to comment.