Skip to content

Commit

Permalink
fix(binding): Don't try metadata lookups on internal and struct types
Browse files Browse the repository at this point in the history
This change reduces the number of false positives for debugging messages on bindable metadata provider types.
  • Loading branch information
jeromelaban committed Jun 15, 2021
1 parent b64a6cb commit 148ccc6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Uno.UI/DataBinding/BindingPropertyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private static bool InternalIsEvent(Type type, string property)
using (Performance.Measure("InternalGetPropertyType"))
#endif
{
if (BindableMetadataProvider != null)
if (IsValidMetadataProviderType(type) && BindableMetadataProvider != null)
{
var bindablePropertyDescriptor = BindablePropertyDescriptor.GetPropertByBindableMetadataProvider(type, property);

Expand Down Expand Up @@ -321,7 +321,7 @@ private static bool InternalIsEvent(Type type, string property)
return attachedPropertyGetter.ReturnType;
}

if(type.IsPrimitive && property == "Value")
if (type.IsPrimitive && property == "Value")
{
// This case is trying assuming that Value for a primitive is used for the case
// of a Nullable primitive.
Expand Down Expand Up @@ -509,7 +509,7 @@ private static ValueGetterHandler InternalGetValueGetter(Type type, string prope
}

// Start by using the provider, to avoid reflection
if (BindableMetadataProvider != null)
if (IsValidMetadataProviderType(type) && BindableMetadataProvider != null)
{
#if PROFILE
using (Performance.Measure("GetValueGetter.BindableMetadataProvider"))
Expand Down Expand Up @@ -579,7 +579,7 @@ private static ValueGetterHandler InternalGetValueGetter(Type type, string prope
}

// Start by using the provider, to avoid reflection
if (BindableMetadataProvider != null)
if (IsValidMetadataProviderType(type) && BindableMetadataProvider != null)
{
#if PROFILE
using (Performance.Measure("GetValueGetter.BindableMetadataProvider"))
Expand Down Expand Up @@ -760,7 +760,7 @@ private static ValueSetterHandler InternalGetValueSetter(Type type, string prope


// Start by using the provider, to avoid reflection
if (BindableMetadataProvider != null)
if (IsValidMetadataProviderType(type) && BindableMetadataProvider != null)
{
#if PROFILE
using (Performance.Measure("GetValueSetter.BindableMetadataProvider"))
Expand Down Expand Up @@ -829,7 +829,7 @@ private static ValueSetterHandler InternalGetValueSetter(Type type, string prope
}

// Start by using the provider, to avoid reflection
if (BindableMetadataProvider != null)
if (IsValidMetadataProviderType(type) && BindableMetadataProvider != null)
{
#if PROFILE
using (Performance.Measure("GetValueSetter.BindableMetadataProvider"))
Expand Down Expand Up @@ -1088,6 +1088,13 @@ private static object UnsetValueGetter(object unused)
=> DependencyProperty.UnsetValue;

private static void UnsetValueSetter(object unused, object? unused2) { }

/// <summary>
/// Determines if the type can be provided by the MetadataProvider
/// </summary>
/// <remarks>This method needs to be aligned with the symbols query in BindableTypeProvidersSourceGenerator.</remarks>
private static bool IsValidMetadataProviderType(Type type)
=> type.IsPublic && type.IsClass;
}
}
#endif

0 comments on commit 148ccc6

Please sign in to comment.