未验证 提交 6619e1b9 编写于 作者: M Michal Strehovský 提交者: GitHub

Remove `CustomAttributeData` usage in IsByRefLike (#80841)

Grabbing custom attribute data brings the entire reflection stack (we need properties, constructors, fields, methods).

We ask `IsByRefLike` in type loader constraint validation. Ideally we should be able to get rid of the type loader from a hello world, but that's for later. This is a more efficient implementation either way.
上级 88ab5ba6
......@@ -38,6 +38,25 @@ public sealed override Assembly Assembly
}
}
public sealed override bool IsByRefLike
{
get
{
// If we have a type handle, ask the runtime
RuntimeTypeHandle typeHandle = InternalTypeHandleIfAvailable;
if (!typeHandle.IsNull)
return Internal.Runtime.Augments.RuntimeAugments.IsByRefLike(typeHandle);
// Otherwise fall back to attributes
foreach (CustomAttributeHandle cah in _typeDefinition.CustomAttributes)
{
if (cah.IsCustomAttributeOfType(_reader, "System.Runtime.CompilerServices", "IsByRefLikeAttribute"))
return true;
}
return false;
}
}
protected sealed override Guid? ComputeGuidFromCustomAttributes()
{
//
......
......@@ -60,6 +60,14 @@ public sealed override IEnumerable<CustomAttributeData> CustomAttributes
}
}
public sealed override bool IsByRefLike
{
get
{
return Internal.Runtime.Augments.RuntimeAugments.IsByRefLike(_typeHandle);
}
}
public sealed override string FullName
{
get
......
......@@ -34,6 +34,7 @@ private RuntimeCLSIDTypeInfo(Guid clsid, string server)
public sealed override string Namespace => BaseType.Namespace;
public sealed override StructLayoutAttribute StructLayoutAttribute => BaseType.StructLayoutAttribute;
public sealed override string ToString() => BaseType.ToString();
public sealed override bool IsByRefLike => false;
public sealed override IEnumerable<CustomAttributeData> CustomAttributes
{
......
......@@ -26,22 +26,7 @@ internal abstract class RuntimeTypeDefinitionTypeInfo : RuntimeTypeInfo
public sealed override bool IsGenericTypeParameter => false;
public sealed override bool IsGenericMethodParameter => 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;
}
}
public abstract override bool IsByRefLike { get; }
// Left unsealed as RuntimeCLSIDTypeInfo has special behavior and needs to override.
public override bool HasSameMetadataDefinitionAs(MemberInfo other)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册