Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ where field.IsStatic
writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.SuppressMessage(\"Microsoft.Maintainability\", \"CA1502:AvoidExcessiveComplexity\", Justification=\"Must be ignored even if generated code is checked.\")]");
writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.SuppressMessage(\"Microsoft.Maintainability\", \"CA1506:AvoidExcessiveClassCoupling\", Justification = \"Must be ignored even if generated code is checked.\")]");
writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.SuppressMessage(\"Microsoft.Maintainability\", \"CA1505:AvoidUnmaintainableCode\", Justification = \"Must be ignored even if generated code is checked.\")]");
writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2111\", Justification = \"`typeof(Type)` emits IL2111 because of `Type.TypeInitializer`, which is not used.\")]");
using (writer.BlockInvariant("internal static global::Uno.UI.DataBinding.IBindableType Build(global::Uno.UI.DataBinding.BindableType parent)"))
{
RegisterHintMethod($"MetadataBuilder_{typeInfo.Index:000}", ownerType, "Uno.UI.DataBinding.IBindableType Build(Uno.UI.DataBinding.BindableType)");
Expand Down
8 changes: 7 additions & 1 deletion src/Uno.UI/DataBinding/BindableProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -24,7 +25,11 @@ public BindableProperty(DependencyProperty property)
/// <summary>
/// This ctor is available for backward compatibility. On newer versions of Uno.UI, the BindableTypeProvidersSourceGenerator uses the single-parameter ctor
/// </summary>
public BindableProperty(Type propertyType, PropertyGetterHandler getter, PropertySetterHandler? setter)
public BindableProperty(
[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
Type propertyType,
PropertyGetterHandler getter,
PropertySetterHandler? setter)
{
Getter = getter;
Setter = setter;
Expand All @@ -35,6 +40,7 @@ public BindableProperty(Type propertyType, PropertyGetterHandler getter, Propert

public PropertySetterHandler? Setter { get; }

[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
public Type PropertyType { get; }

public DependencyProperty? DependencyProperty { get; }
Expand Down
25 changes: 22 additions & 3 deletions src/Uno.UI/DataBinding/BindableType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -16,6 +17,13 @@ namespace Uno.UI.DataBinding
/// </summary>
public class BindableType : IBindableType
{
internal const DynamicallyAccessedMemberTypes TypeRequirements =
DynamicallyAccessedMemberTypes.NonPublicConstructors // DependencyProperty.Register()
| DynamicallyAccessedMemberTypes.PublicConstructors
| DynamicallyAccessedMemberTypes.PublicFields
| DynamicallyAccessedMemberTypes.PublicProperties
;

private readonly Hashtable _properties;
private StringIndexerGetterDelegate? _stringIndexerGetter;
private StringIndexerSetterDelegate? _stringIndexerSetter;
Expand All @@ -26,12 +34,16 @@ public class BindableType : IBindableType
/// </summary>
/// <param name="estimatedPropertySize">Provide an estimated number of properties, so the dictionary does not need to grow unnecessarily.</param>
/// <param name="sourceType">The actual .NET type that corresponds to this instance.</param>
public BindableType(int estimatedPropertySize, Type sourceType)
public BindableType(
int estimatedPropertySize,
[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
Type sourceType)
{
_properties = new Hashtable(estimatedPropertySize);
Type = sourceType;
}

[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
public Type Type { get; }

public ActivatorDelegate? CreateInstance()
Expand Down Expand Up @@ -61,7 +73,9 @@ public void AddActivator(ActivatorDelegate activator)
_activator = activator;
}

public void AddProperty<T>(string name, PropertyGetterHandler getter, PropertySetterHandler? setter = null)
public void AddProperty<
[DynamicallyAccessedMembers(TypeRequirements)] T
>(string name, PropertyGetterHandler getter, PropertySetterHandler? setter = null)
{
_properties[name] = new BindableProperty(typeof(T), getter, setter);
}
Expand All @@ -71,7 +85,12 @@ public void AddProperty(DependencyProperty property)
_properties[property.Name] = new BindableProperty(property);
}

public void AddProperty(string name, Type propertyType, PropertyGetterHandler getter, PropertySetterHandler? setter = null)
public void AddProperty(
string name,
[DynamicallyAccessedMembers(TypeRequirements)]
Type propertyType,
PropertyGetterHandler getter,
PropertySetterHandler? setter = null)
{
_properties[name] = new BindableProperty(propertyType, getter, setter);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI/DataBinding/IBindableProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;

Expand All @@ -26,6 +27,7 @@ public interface IBindableProperty
/// <summary>
/// Gets the type of the property
/// </summary>
[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
Type PropertyType { get; }

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI/DataBinding/IBindableType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -31,6 +32,7 @@ public interface IBindableType
/// <summary>
/// Provides the Type of this bindable type
/// </summary>
[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
Type Type { get; }

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Frame/Frame.Properties.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.UI.Xaml.Navigation;

namespace Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -117,6 +118,8 @@ public Type CurrentSourcePageType
/// <summary>
/// Identifies the CurrentSourcePageType dependency property.
/// </summary>
[UnconditionalSuppressMessage("Trimming", "IL2111", Justification = "`typeof(Type)` triggers IL2111 regarding `Type.TypeInitializer`, but Uno doesn't use `Type.TypeInitializer`!")]
// warning IL2111: Method 'System.Type.TypeInitializer.get' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method.
public static DependencyProperty CurrentSourcePageTypeProperty { get; } =
DependencyProperty.Register(
nameof(CurrentSourcePageType),
Expand Down Expand Up @@ -174,6 +177,8 @@ public Type SourcePageType
/// <summary>
/// Identifies the SourcePageType dependency property.
/// </summary>
[UnconditionalSuppressMessage("Trimming", "IL2111", Justification = "`typeof(Type)` triggers IL2111 regarding `Type.TypeInitializer`, but Uno doesn't use `Type.TypeInitializer`!")]
// warning IL2111: Method 'System.Type.TypeInitializer.get' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method.
public static DependencyProperty SourcePageTypeProperty { get; } =
DependencyProperty.Register(
nameof(SourcePageType),
Expand Down
26 changes: 19 additions & 7 deletions src/Uno.UI/UI/Xaml/DependencyProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Uno;
using Uno.Extensions;
using Uno.UI;
using Uno.UI.DataBinding;
using Uno.UI.Dispatching;
using Uno.UI.Helpers;
using Uno.UI.Xaml.Media;
Expand Down Expand Up @@ -54,13 +55,22 @@ public sealed partial class DependencyProperty

private readonly Flags _flags;
private string _name;
[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
private Type _propertyType;
[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
private Type _ownerType;
private readonly int _uniqueId;

private static int _globalId = -1;

private DependencyProperty(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, bool attached)
private DependencyProperty(
string name,
[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
Type propertyType,
[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
Type ownerType,
PropertyMetadata defaultMetadata,
bool attached)
{
_name = name;
_propertyType = propertyType;
Expand Down Expand Up @@ -140,8 +150,8 @@ internal bool IsDependencyObjectCollection
/// <exception cref="InvalidOperationException">A property with the same name has already been declared for the ownerType</exception>
public static DependencyProperty Register(
string name,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type propertyType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type ownerType,
[DynamicallyAccessedMembers(BindableType.TypeRequirements)] Type propertyType,
[DynamicallyAccessedMembers(BindableType.TypeRequirements)] Type ownerType,
PropertyMetadata typeMetadata)
{
typeMetadata = FixMetadataIfNeeded(propertyType, typeMetadata);
Expand Down Expand Up @@ -196,8 +206,8 @@ private static PropertyMetadata FixMetadataIfNeeded(
/// </remarks>
internal static DependencyProperty Register(
string name,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type propertyType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type ownerType,
[DynamicallyAccessedMembers(BindableType.TypeRequirements)] Type propertyType,
[DynamicallyAccessedMembers(BindableType.TypeRequirements)] Type ownerType,
FrameworkPropertyMetadata typeMetadata)
#pragma warning disable RS0030 // Do not used banned APIs
=> Register(name, propertyType, ownerType, (PropertyMetadata)typeMetadata);
Expand All @@ -214,8 +224,8 @@ internal static DependencyProperty Register(
/// <exception cref="InvalidOperationException">A property with the same name has already been declared for the ownerType</exception>
public static DependencyProperty RegisterAttached(
string name,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type propertyType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type ownerType,
[DynamicallyAccessedMembers(BindableType.TypeRequirements)] Type propertyType,
[DynamicallyAccessedMembers(BindableType.TypeRequirements)] Type ownerType,
PropertyMetadata defaultMetadata)
{
defaultMetadata = FixMetadataIfNeeded(propertyType, defaultMetadata);
Expand Down Expand Up @@ -297,11 +307,13 @@ public PropertyMetadata GetMetadata(Type forType)
return _ownerTypeMetadata.CloneWithOverwrittenDefaultValue(defaultValueForType);
}

[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
internal Type OwnerType
{
get { return _ownerType; }
}

[DynamicallyAccessedMembers(BindableType.TypeRequirements)]
internal Type Type
{
get { return _propertyType; }
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.UI/UI/Xaml/Navigation/PageStackEntry.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public Type SourcePageType
/// <summary>
/// Identifies the SourcePageType dependency property.
/// </summary>
[UnconditionalSuppressMessage("Trimming", "IL2111", Justification = "@jonpryor has no idea what the trimmer is talking about.")]
[UnconditionalSuppressMessage("Trimming", "IL2111", Justification = "`typeof(Type)` triggers IL2111 regarding `Type.TypeInitializer`, but Uno doesn't use `Type.TypeInitializer`!")]
// warning IL2111: Method 'System.Type.TypeInitializer.get' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method.
public static DependencyProperty SourcePageTypeProperty { get; } =
DependencyProperty.Register(
nameof(SourcePageType),
Expand Down
Loading