diff options
author | Atsushi Kanamori <AtsushiKan@users.noreply.github.com> | 2017-07-24 19:37:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-24 19:37:35 +0300 |
commit | bcd5d00b66d31eebfae68d0f98c6530b5c0ae0da (patch) | |
tree | 73ce7cc8fce8e80453a78c18d523409f51565d7d /src/System.Private.Reflection.Core | |
parent | f6d56a27f2c545c7bf50d029217fd561fa9454e3 (diff) |
Implement IsByRefLike on System.Type (#4221)
This is sitting around in the api review queue
but we don't need to block on that to have an
implementation. We're going to need to start
enforcing this in various apis.
Notes:
IsByRef != IsByRefLike (this matches
the EEType property definition and
avoids overlapping concerns.)
My read of the Span safety docs
is that the [IsByRefLike] attribute
is required before you can embed
IsByRefLike fields - hence, no need
for IsByRefLike to check each field.
There's some inconsistency in the behavior
regarding [IsByRefLike] attributes applied
by hand to types that don't actually have
IsByRefLike behavior. EETypePtr.IsByRefLike
and MethodTable::IsByRefLike (CoreCLR)
don't report these as IsByRefLike but
the metadata fallback for BrowseOnly
types will.
Diffstat (limited to 'src/System.Private.Reflection.Core')
5 files changed, 26 insertions, 0 deletions
diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs index 3f2d8ad36..80923ee31 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs @@ -39,6 +39,7 @@ namespace System.Reflection.Runtime.TypeInfos protected sealed override bool IsPointerImpl() => false; public sealed override bool IsConstructedGenericType => true; public sealed override bool IsGenericParameter => false; + public sealed override bool IsByRefLike => GenericTypeDefinitionTypeInfo.IsByRefLike; // // Implements IKeyedItem.PrepareKey. diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeGenericParameterTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeGenericParameterTypeInfo.cs index fb030e856..241878768 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeGenericParameterTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeGenericParameterTypeInfo.cs @@ -35,6 +35,7 @@ namespace System.Reflection.Runtime.TypeInfos protected sealed override bool IsPointerImpl() => false; public sealed override bool IsConstructedGenericType => false; public sealed override bool IsGenericParameter => true; + public sealed override bool IsByRefLike => false; public sealed override Assembly Assembly { diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeHasElementTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeHasElementTypeInfo.cs index e01f8f584..88ee72d35 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeHasElementTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeHasElementTypeInfo.cs @@ -36,6 +36,7 @@ namespace System.Reflection.Runtime.TypeInfos protected abstract override bool IsPointerImpl(); public sealed override bool IsConstructedGenericType => false; public sealed override bool IsGenericParameter => false; + public sealed override bool IsByRefLike => false; // // Implements IKeyedItem.PrepareKey. diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeDefinitionTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeDefinitionTypeInfo.cs index 0ab216de2..983a81cab 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeDefinitionTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeDefinitionTypeInfo.cs @@ -2,6 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.CompilerServices; +using System.Reflection.Runtime.General; + +using Internal.Runtime.Augments; + namespace System.Reflection.Runtime.TypeInfos { // @@ -20,6 +25,23 @@ namespace System.Reflection.Runtime.TypeInfos public sealed override bool IsConstructedGenericType => false; public sealed override bool IsGenericParameter => false; + public sealed override bool IsByRefLike + { + get + { + RuntimeTypeHandle typeHandle = InternalTypeHandleIfAvailable; + if (!typeHandle.IsNull()) + return RuntimeAugments.IsByRefLike(typeHandle); + + foreach (CustomAttributeData cad in CustomAttributes) + { + if (cad.AttributeType == typeof(IsByRefLikeAttribute)) + return true; + } + return false; + } + } + // Left unsealed as RuntimeCLSIDTypeInfo has special behavior and needs to override. public override bool HasSameMetadataDefinitionAs(MemberInfo other) { diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs index 6d816e0a5..be3686823 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs @@ -52,6 +52,7 @@ namespace System.Reflection.Runtime.TypeInfos protected abstract override bool IsPointerImpl(); public abstract override bool IsGenericParameter { get; } public abstract override bool IsConstructedGenericType { get; } + public abstract override bool IsByRefLike { get; } public abstract override Assembly Assembly { get; } |