本文整理汇总了C#中System.Reflection.Metadata.MetadataReader.GetTypeDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataReader.GetTypeDefinition方法的具体用法?C# MetadataReader.GetTypeDefinition怎么用?C# MetadataReader.GetTypeDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Metadata.MetadataReader
的用法示例。
在下文中一共展示了MetadataReader.GetTypeDefinition方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAnonymousTypeMap
private static IReadOnlyDictionary<AnonymousTypeKey, AnonymousTypeValue> GetAnonymousTypeMap(
MetadataReader reader,
Symbols.Metadata.PE.MetadataDecoder metadataDecoder)
{
var result = new Dictionary<AnonymousTypeKey, AnonymousTypeValue>();
foreach (var handle in reader.TypeDefinitions)
{
var def = reader.GetTypeDefinition(handle);
if (!def.Namespace.IsNil)
{
continue;
}
if (!reader.StringStartsWith(def.Name, GeneratedNames.AnonymousNamePrefix))
{
continue;
}
var metadataName = reader.GetString(def.Name);
short arity;
var name = MetadataHelpers.InferTypeArityAndUnmangleMetadataName(metadataName, out arity);
int index;
if (GeneratedNames.TryParseAnonymousTypeTemplateName(name, out index))
{
var builder = ArrayBuilder<string>.GetInstance();
if (TryGetAnonymousTypeKey(reader, def, builder))
{
var type = (NamedTypeSymbol)metadataDecoder.GetTypeOfToken(handle);
var key = new AnonymousTypeKey(builder.ToImmutable());
var value = new AnonymousTypeValue(name, index, type);
result.Add(key, value);
}
builder.Free();
}
}
return result;
}
示例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: GetFullName
private static string GetFullName(MetadataReader reader, TypeDefinition type)
{
var typeName = reader.GetString(type.Name);
if (TypeAttributes.NestedPublic == (type.Attributes & TypeAttributes.NestedPublic))
{
// Need to take into account the containing type.
var declaringType = reader.GetTypeDefinition(type.GetDeclaringType());
var declaringTypeFullName = GetFullName(reader, declaringType);
return $"{declaringTypeFullName}+{typeName}";
}
var namespaceName = reader.GetString(type.Namespace);
if (string.IsNullOrEmpty(namespaceName))
{
return typeName;
}
return $"{namespaceName}.{typeName}";
}
示例4: GetTypeInfoList
private static List<TypeInfo> GetTypeInfoList(MetadataReader reader)
{
var list = new List<TypeInfo>();
foreach (var handle in reader.TypeDefinitions)
{
var type = reader.GetTypeDefinition(handle);
if (!IsValidIdentifier(reader, type.Name))
{
continue;
}
var methodCount = GetMethodCount(reader, type);
if (!ShouldIncludeType(reader, type, methodCount))
{
continue;
}
var fullName = GetFullName(reader, type);
list.Add(new TypeInfo(fullName, methodCount));
}
// Ensure we get classes back in a deterministic order.
list.Sort((x, y) => x.FullName.CompareTo(y.FullName));
return list;
}
示例5: GetFullTypeNames
internal static IEnumerable<string> GetFullTypeNames(MetadataReader metadataReader)
{
foreach (var typeDefHandle in metadataReader.TypeDefinitions)
{
var typeDef = metadataReader.GetTypeDefinition(typeDefHandle);
var ns = metadataReader.GetString(typeDef.Namespace);
var name = metadataReader.GetString(typeDef.Name);
yield return (ns.Length == 0) ? name : (ns + "." + name);
}
}
示例6: GetTokenForType
private static TypeHandle GetTokenForType(MetadataReader metadataReader, string typeName)
{
Assert.NotNull(typeName);
Assert.NotEmpty(typeName);
foreach (var typeDef in metadataReader.TypeDefinitions)
{
string name = metadataReader.GetString(metadataReader.GetTypeDefinition(typeDef).Name);
if (typeName.Equals(name))
{
return typeDef;
}
}
AssertEx.Fail("Unable to find type:" + typeName);
return default(TypeHandle);
}
示例7: LookupMetadataDefinitions
private static void LookupMetadataDefinitions(
MetadataReader reader, NamespaceDefinition namespaceDefinition,
OrderPreservingMultiDictionary<string, MetadataDefinition> definitionMap)
{
foreach (var child in namespaceDefinition.NamespaceDefinitions)
{
var definition = MetadataDefinition.Create(reader, child);
definitionMap.Add(definition.Name, definition);
}
foreach (var child in namespaceDefinition.TypeDefinitions)
{
var typeDefinition = reader.GetTypeDefinition(child);
if (IsPublic(typeDefinition.Attributes))
{
var definition = MetadataDefinition.Create(reader, typeDefinition);
definitionMap.Add(definition.Name, definition);
}
}
}
示例8: GetAttributeParentNameAndKind
private static void GetAttributeParentNameAndKind(MetadataReader metadataReader, Handle token, out string name, out SymbolKind kind)
{
switch (token.HandleType)
{
case HandleType.Assembly:
name = null;
kind = SymbolKind.Assembly;
return;
case HandleType.Type:
name = metadataReader.GetString(metadataReader.GetTypeDefinition((TypeHandle)token).Name);
kind = SymbolKind.NamedType;
return;
case HandleType.Method:
name = metadataReader.GetString(metadataReader.GetMethod((MethodHandle)token).Name);
kind = SymbolKind.Method;
return;
default:
throw TestExceptionUtilities.UnexpectedValue(token.HandleType);
}
}
示例9: 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)));
}
示例10: GetTypeFullName
/// <summary>
/// Get the full name of a Type.
/// </summary>
private static string GetTypeFullName(MetadataReader metadataReader, TypeDefinition typeDefinition)
{
string fullName;
string typeName = metadataReader.GetString(typeDefinition.Name);
string nsName = metadataReader.GetString(typeDefinition.Namespace);
// Get the enclosing type if the type is nested
TypeDefinitionHandle declaringTypeHandle = typeDefinition.GetDeclaringType();
if (declaringTypeHandle.IsNil)
{
fullName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", nsName, typeName);
}
else
{
fullName = typeName;
while (!declaringTypeHandle.IsNil)
{
TypeDefinition declaringTypeDef = metadataReader.GetTypeDefinition(declaringTypeHandle);
declaringTypeHandle = declaringTypeDef.GetDeclaringType();
if (declaringTypeHandle.IsNil)
{
fullName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}+{2}",
metadataReader.GetString(declaringTypeDef.Namespace),
metadataReader.GetString(declaringTypeDef.Name),
fullName);
}
else
{
fullName = string.Format(CultureInfo.InvariantCulture, "{0}+{1}",
metadataReader.GetString(declaringTypeDef.Name),
fullName);
}
}
}
return fullName;
}
示例11: IsPubliclyVisible
private bool IsPubliclyVisible(MetadataReader referenceMetadata, MethodDefinition methodDefinition, bool checkDeclaringType = false)
{
switch (methodDefinition.Attributes & MethodAttributes.MemberAccessMask)
{
case MethodAttributes.Public:
case MethodAttributes.Family:
case MethodAttributes.FamORAssem:
break;
case MethodAttributes.FamANDAssem:
case MethodAttributes.Assembly:
case MethodAttributes.Private:
case MethodAttributes.PrivateScope:
default:
return false;
}
if (checkDeclaringType)
{
TypeDefinition declaringTypeDefinition = referenceMetadata.GetTypeDefinition(methodDefinition.GetDeclaringType());
if (!IsPubliclyVisible(referenceMetadata, declaringTypeDefinition))
return false;
}
return true;
}
示例12: GetMetadataName
private string GetMetadataName(MetadataReader metadataReader, MethodDefinition methodDefinition)
{
TypeDefinition declaringTypeDefinition = metadataReader.GetTypeDefinition(methodDefinition.GetDeclaringType());
string typeName = GetMetadataName(metadataReader, declaringTypeDefinition);
string methodName = metadataReader.GetString(methodDefinition.Name);
return string.Format("{0}.{1}", typeName, methodName);
}