Skip to content

Commit 91d702c

Browse files
Use Type.IsByRefLike. (#48351)
* Use `Type.IsByRefLike`. * Inline `IsRefStructProperty`; it is used only once and is small.
1 parent add60ed commit 91d702c

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

src/Shared/PropertyHelper/PropertyHelper.cs

+5-16
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ internal sealed class PropertyHelper
4242

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

45-
private static readonly Type IsByRefLikeAttribute = typeof(System.Runtime.CompilerServices.IsByRefLikeAttribute);
46-
4745
private Action<object, object?>? _valueSetter;
4846
private Func<object, object?>? _valueGetter;
4947

@@ -552,25 +550,16 @@ private static bool IsInterestingProperty(PropertyInfo property)
552550
property.GetMethod.IsPublic &&
553551
!property.GetMethod.IsStatic &&
554552

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

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

562-
// PropertyHelper can't really interact with ref-struct properties since they can't be
563-
// boxed and can't be used as generic types. We just ignore them.
564-
//
565-
// see: https://github.com/aspnet/Mvc/issues/8545
566-
private static bool IsRefStructProperty(PropertyInfo property)
567-
{
568-
return
569-
IsByRefLikeAttribute != null &&
570-
property.PropertyType.IsValueType &&
571-
property.PropertyType.IsDefined(IsByRefLikeAttribute);
572-
}
573-
574563
internal static class MetadataUpdateHandler
575564
{
576565
/// <summary>

0 commit comments

Comments
 (0)