Skip to content

Commit

Permalink
Use Type.IsByRefLike. (dotnet#48351)
Browse files Browse the repository at this point in the history
* Use `Type.IsByRefLike`.

* Inline `IsRefStructProperty`; it is used only once and is small.
  • Loading branch information
teo-tsirpanis authored May 24, 2023
1 parent add60ed commit 91d702c
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/Shared/PropertyHelper/PropertyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ internal sealed class PropertyHelper

private static readonly ConcurrentDictionary<Type, PropertyHelper[]> VisiblePropertiesCache = new();

private static readonly Type IsByRefLikeAttribute = typeof(System.Runtime.CompilerServices.IsByRefLikeAttribute);

private Action<object, object?>? _valueSetter;
private Func<object, object?>? _valueGetter;

Expand Down Expand Up @@ -552,25 +550,16 @@ private static bool IsInterestingProperty(PropertyInfo property)
property.GetMethod.IsPublic &&
!property.GetMethod.IsStatic &&

// PropertyHelper can't work with ref structs.
!IsRefStructProperty(property) &&
// PropertyHelper can't really interact with ref-struct properties since they can't be
// boxed and can't be used as generic types. We just ignore them.
//
// see: https://github.com/aspnet/Mvc/issues/8545
!property.PropertyType.IsByRefLike &&

// Indexed properties are not useful (or valid) for grabbing properties off an object.
property.GetMethod.GetParameters().Length == 0;
}

// PropertyHelper can't really interact with ref-struct properties since they can't be
// boxed and can't be used as generic types. We just ignore them.
//
// see: https://github.com/aspnet/Mvc/issues/8545
private static bool IsRefStructProperty(PropertyInfo property)
{
return
IsByRefLikeAttribute != null &&
property.PropertyType.IsValueType &&
property.PropertyType.IsDefined(IsByRefLikeAttribute);
}

internal static class MetadataUpdateHandler
{
/// <summary>
Expand Down

0 comments on commit 91d702c

Please sign in to comment.