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


C# MetadataReader.GetTypeReference方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:18,代码来源:MetadataValidation.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: 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";
        }
开发者ID:Eyas,项目名称:roslyn,代码行数:12,代码来源:AssemblyScheduler.cs

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

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

示例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);
 }
开发者ID:leloulight,项目名称:dnx,代码行数:6,代码来源:DnuPackTests.cs

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


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