本文整理汇总了C#中System.Reflection.Metadata.MetadataReader.GetTypeReference方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataReader.GetTypeReference方法的具体用法?C# MetadataReader.GetTypeReference怎么用?C# MetadataReader.GetTypeReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Metadata.MetadataReader
的用法示例。
在下文中一共展示了MetadataReader.GetTypeReference方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAttributeName
/// <summary>
/// Returns the name of the attribute class
/// </summary>
internal static string GetAttributeName(MetadataReader metadataReader, CustomAttributeHandle customAttribute)
{
var ctorHandle = metadataReader.GetCustomAttribute(customAttribute).Constructor;
if (ctorHandle.Kind == HandleKind.MemberReference) // MemberRef
{
var container = metadataReader.GetMemberReference((MemberReferenceHandle)ctorHandle).Parent;
var name = metadataReader.GetTypeReference((TypeReferenceHandle)container).Name;
return metadataReader.GetString(name);
}
else
{
Assert.True(false, "not impl");
return null;
}
}
示例2: TryGetAttributeName
/// <summary>Gets the name of an attribute.</summary>
/// <param name="reader">The metadata reader.</param>
/// <param name="attr">The attribute.</param>
/// <param name="typeNamespaceHandle">The namespace of the attribute.</param>
/// <param name="typeNameHandle">The name of the attribute.</param>
/// <returns>true if the name could be retrieved; otherwise, false.</returns>
private static bool TryGetAttributeName(MetadataReader reader, CustomAttribute attr, out StringHandle typeNamespaceHandle, out StringHandle typeNameHandle)
{
EntityHandle ctorHandle = attr.Constructor;
switch (ctorHandle.Kind)
{
case HandleKind.MemberReference:
EntityHandle container = reader.GetMemberReference((MemberReferenceHandle)ctorHandle).Parent;
if (container.Kind == HandleKind.TypeReference)
{
TypeReference tr = reader.GetTypeReference((TypeReferenceHandle)container);
typeNamespaceHandle = tr.Namespace;
typeNameHandle = tr.Name;
return true;
}
break;
case HandleKind.MethodDefinition:
MethodDefinition md = reader.GetMethodDefinition((MethodDefinitionHandle)ctorHandle);
TypeDefinition td = reader.GetTypeDefinition(md.GetDeclaringType());
typeNamespaceHandle = td.Namespace;
typeNameHandle = td.Name;
return true;
}
// Unusual case, potentially invalid IL
typeNamespaceHandle = default(StringHandle);
typeNameHandle = default(StringHandle);
return false;
}
示例3: InheritsFromObject
private static bool? InheritsFromObject(MetadataReader reader, TypeDefinition type)
{
if (type.BaseType.Kind != HandleKind.TypeReference)
{
return null;
}
var typeRef = reader.GetTypeReference((TypeReferenceHandle)type.BaseType);
return
reader.GetString(typeRef.Namespace) == "System" &&
reader.GetString(typeRef.Name) == "Object";
}
示例4: DumpTypeRefs
private static IEnumerable<string> DumpTypeRefs(MetadataReader reader)
{
foreach (var typeRefHandle in reader.TypeReferences)
{
var typeRef = reader.GetTypeReference(typeRefHandle);
yield return $"[0x{MetadataTokens.GetToken(typeRef.ResolutionScope):x8}] 0x{MetadataTokens.GetHeapOffset(typeRef.Namespace):x8}.0x{MetadataTokens.GetHeapOffset(typeRef.Name):x8}";
}
}
示例5: GetFullTypeName
private static string GetFullTypeName(MetadataReader metadataReader, Handle handle)
{
if (handle.IsNil)
{
return null;
}
if (handle.HandleType == HandleType.Type)
{
var type = metadataReader.GetTypeDefinition((TypeHandle)handle);
string name = metadataReader.GetString(type.Name);
while (IsNested(type.Attributes))
{
var enclosingType = metadataReader.GetTypeDefinition(type.GetDeclaringType());
name = metadataReader.GetString(enclosingType.Name) + "+" + name;
type = enclosingType;
}
if (type.Namespace.IsNil)
{
return name;
}
return metadataReader.GetString(type.Namespace) + "." + name;
}
if (handle.HandleType == HandleType.TypeReference)
{
var typeRef = metadataReader.GetTypeReference((TypeReferenceHandle)handle);
string name = metadataReader.GetString(typeRef.Name);
if (typeRef.Namespace.IsNil)
{
return name;
}
return metadataReader.GetString(typeRef.Namespace) + "." + name;
}
return string.Format("<unexpected token kind: {0}>", AsToken(metadataReader.GetToken(handle)));
}
示例6: GetAttributeName
private string GetAttributeName(CustomAttribute attribute, MetadataReader metadataReader)
{
var container = metadataReader.GetMemberReference((MemberReferenceHandle)attribute.Constructor).Parent;
var name = metadataReader.GetTypeReference((TypeReferenceHandle)container).Name;
return metadataReader.GetString(name);
}
示例7: IsSameType
private bool IsSameType(MetadataReader referenceMetadata, MetadataReader newMetadata, Handle referenceTypeHandle, Handle newTypeHandle)
{
if (referenceTypeHandle.IsNil != newTypeHandle.IsNil)
return false;
if (referenceTypeHandle.Kind != newTypeHandle.Kind)
return false;
switch (referenceTypeHandle.Kind)
{
case HandleKind.TypeDefinition:
Mapping<TypeDefinitionHandle> mappedTypeDefinitionHandle = _referenceToNewMapping.MapTypeDefinition((TypeDefinitionHandle)referenceTypeHandle);
if (mappedTypeDefinitionHandle.Target.IsNil)
return false;
return mappedTypeDefinitionHandle.Target == (TypeDefinitionHandle)newTypeHandle;
case HandleKind.TypeReference:
TypeReference referenceTypeReference = referenceMetadata.GetTypeReference((TypeReferenceHandle)referenceTypeHandle);
TypeReference newTypeReference = newMetadata.GetTypeReference((TypeReferenceHandle)newTypeHandle);
return IsSameType(referenceMetadata, newMetadata, referenceTypeReference, newTypeReference);
case HandleKind.TypeSpecification:
TypeSpecification referenceTypeSpecification = referenceMetadata.GetTypeSpecification((TypeSpecificationHandle)referenceTypeHandle);
TypeSpecification newTypeSpecification = newMetadata.GetTypeSpecification((TypeSpecificationHandle)newTypeHandle);
return IsSameType(referenceMetadata, newMetadata, referenceTypeSpecification, newTypeSpecification);
default:
throw new InvalidOperationException("Invalid type handle.");
}
}