当前位置: 首页>>代码示例>>C#>>正文


C# MetadataReader.GetTypeDefinition方法代码示例

本文整理汇总了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;
 }
开发者ID:pheede,项目名称:roslyn,代码行数:35,代码来源:PEDeltaAssemblyBuilder.cs

示例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;
        }
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:35,代码来源:FileVersionInfo.Metadata.cs

示例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}";
        }
开发者ID:Eyas,项目名称:roslyn,代码行数:20,代码来源:AssemblyScheduler.cs

示例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;
        }
开发者ID:Eyas,项目名称:roslyn,代码行数:25,代码来源:AssemblyScheduler.cs

示例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);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:11,代码来源:MetadataValidation.cs

示例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);
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:18,代码来源:EmitMetadataTestBase.cs

示例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);
                }
            }
        }
开发者ID:swaroop-sridhar,项目名称:roslyn,代码行数:20,代码来源:SymbolTreeInfo_Metadata.cs

示例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);

            }
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:24,代码来源:EmitMetadataTestBase.cs

示例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)));
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:41,代码来源:PdbToXml.cs

示例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;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:40,代码来源:TypeCatalogGen.cs

示例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;
        }
开发者ID:modulexcite,项目名称:dotnet-compatibility,代码行数:26,代码来源:Analyzer.cs

示例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);
 }
开发者ID:modulexcite,项目名称:dotnet-compatibility,代码行数:7,代码来源:Analyzer.cs


注:本文中的System.Reflection.Metadata.MetadataReader.GetTypeDefinition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。