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


C# MetadataReader.GetString方法代码示例

本文整理汇总了C#中System.Reflection.Metadata.MetadataReader.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataReader.GetString方法的具体用法?C# MetadataReader.GetString怎么用?C# MetadataReader.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Metadata.MetadataReader的用法示例。


在下文中一共展示了MetadataReader.GetString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetAssemblyStrongName

        /// <summary>
        /// Construct the strong assembly name from metadata
        /// </summary>
        internal static string GetAssemblyStrongName(MetadataReader metadataReader)
        {
            AssemblyDefinition assemblyDefinition = metadataReader.GetAssemblyDefinition();
            string asmName = metadataReader.GetString(assemblyDefinition.Name);
            string asmVersion = assemblyDefinition.Version.ToString();
            string asmCulture = metadataReader.GetString(assemblyDefinition.Culture);
            asmCulture = (asmCulture == string.Empty) ? "neutral" : asmCulture;

            AssemblyHashAlgorithm hashAlgorithm = assemblyDefinition.HashAlgorithm;
            BlobHandle blobHandle = assemblyDefinition.PublicKey;
            BlobReader blobReader = metadataReader.GetBlobReader(blobHandle);

            string publicKeyTokenString = "null";
            // Extract public key token only if PublicKey exists in the metadata
            if (blobReader.Length > 0)
            {
                byte[] publickey = blobReader.ReadBytes(blobReader.Length);

                HashAlgorithm hashImpl = null;
                switch (hashAlgorithm)
                {
                    case AssemblyHashAlgorithm.Sha1:
                        hashImpl = SHA1.Create();
                        break;
                    case AssemblyHashAlgorithm.MD5:
                        hashImpl = MD5.Create();
                        break;
                    case AssemblyHashAlgorithm.Sha256:
                        hashImpl = SHA256.Create();
                        break;
                    case AssemblyHashAlgorithm.Sha384:
                        hashImpl = SHA384.Create();
                        break;
                    case AssemblyHashAlgorithm.Sha512:
                        hashImpl = SHA512.Create();
                        break;
                    default:
                        throw new NotSupportedException();
                }

                byte[] publicKeyHash = hashImpl.ComputeHash(publickey);
                byte[] publicKeyTokenBytes = new byte[8];
                // Note that, the low 8 bytes of the hash of public key in reverse order is the public key tokens.
                for (int i = 1; i <= 8; i++)
                {
                    publicKeyTokenBytes[i - 1] = publicKeyHash[publicKeyHash.Length - i];
                }

                // Convert bytes to hex format strings in lower case.
                publicKeyTokenString = BitConverter.ToString(publicKeyTokenBytes).Replace("-", string.Empty).ToLowerInvariant();
            }

            string strongAssemblyName = string.Format(CultureInfo.InvariantCulture,
                                                      "{0}, Version={1}, Culture={2}, PublicKeyToken={3}",
                                                      asmName, asmVersion, asmCulture, publicKeyTokenString);

            return strongAssemblyName;
        }
开发者ID:dfinke,项目名称:powershell,代码行数:61,代码来源:AssemblyMetadataHelper.cs

示例2: 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

示例3: GetAssemblyReferences

        private static Reference[] GetAssemblyReferences(MetadataReader reader)
        {
            var references = new List<Reference>();

            foreach (var handle in reader.AssemblyReferences)
            {
                var reference = reader.GetAssemblyReference(handle);
                references.Add(new Reference(reader.GetString(reference.Name), reference.Version));
            }

            return references.ToArray();
        }
开发者ID:modulexcite,项目名称:ReferenceGenerator,代码行数:12,代码来源:AssemblyInfo.cs

示例4: DependencyFinderEngineHelper

        public DependencyFinderEngineHelper(MetadataReader metadataReader, string assemblyPath)
        {
            _reader = metadataReader;
            _assemblyLocation = assemblyPath;

            MemberDependency = new List<MemberDependency>();
            CallingAssembly = _reader.GetAssemblyInfo(assemblyPath);

            // Get assembly info
            var assemblyDefinition = _reader.GetAssemblyDefinition();

            _currentAssemblyInfo = _reader.FormatAssemblyInfo(assemblyDefinition);
            _currentAssemblyName = _reader.GetString(assemblyDefinition.Name);
        }
开发者ID:vivmishra,项目名称:dotnet-apiport,代码行数:14,代码来源:DependencyFinderEngineHelper.cs

示例5: GetMetadataNameWithoutBackticks

        private static string GetMetadataNameWithoutBackticks(MetadataReader reader, StringHandle name)
        {
            var blobReader = reader.GetBlobReader(name);
            var backtickIndex = blobReader.IndexOf((byte)'`');
            if (backtickIndex == -1)
            {
                return reader.GetString(name);
            }

            unsafe
            {
                return MetadataStringDecoder.DefaultUTF8.GetString(
                    blobReader.CurrentPointer, backtickIndex);
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:15,代码来源:SymbolTreeInfo_Metadata.cs

示例6: 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

示例7: DependencyFinderEngineHelper

        public DependencyFinderEngineHelper(IDependencyFilter assemblyFilter, MetadataReader metadataReader, IAssemblyFile file)
        {
            _assemblyFilter = assemblyFilter;
            _reader = metadataReader;
            _assemblyLocation = file.Name;

            MemberDependency = new List<MemberDependency>();
            CallingAssembly = new AssemblyInfo
            {
                AssemblyIdentity = metadataReader.FormatAssemblyInfo().ToString(),
                FileVersion = file.Version ?? string.Empty,
                TargetFrameworkMoniker = metadataReader.GetTargetFrameworkMoniker() ?? string.Empty
            };

            // Get assembly info
            var assemblyDefinition = _reader.GetAssemblyDefinition();

            _currentAssemblyInfo = _reader.FormatAssemblyInfo(assemblyDefinition);
            _currentAssemblyName = _reader.GetString(assemblyDefinition.Name);
        }
开发者ID:MetSystem,项目名称:dotnet-apiport,代码行数:20,代码来源:DependencyFinderEngineHelper.cs

示例8: GetFileName

        private static string GetFileName(MetadataReader reader, DocumentHandle documentHandle)
        {
            var document = reader.GetDocument(documentHandle);

            if (document.Name.IsNil)
            {
                return null;
            }

            var nameReader = reader.GetBlobReader(document.Name);

            int separator = nameReader.ReadByte();
            if (!FileNameUtilities.IsDirectorySeparator((char)separator))
            {
                return FileNameUtilities.GetFileName(reader.GetString(document.Name));
            }

            // find the last part handle:
            BlobHandle partHandle = default(BlobHandle);
            while (nameReader.RemainingBytes > 0)
            {
                partHandle = nameReader.ReadBlobHandle();
            }

            if (partHandle.IsNil)
            {
                return string.Empty;
            }

            var partReader = reader.GetBlobReader(partHandle);
            var part = partReader.ReadUTF8(partReader.Length);
            if (part.IndexOf('\0') >= 0)
            {
                // bad metadata
                return null;
            }

            // it is valid to encode document name so that the parts contain directory separators:
            return FileNameUtilities.GetFileName(part);
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:40,代码来源:DocumentMap.cs

示例9: TryGetAnonymousTypeKey

 private static bool TryGetAnonymousTypeKey(
     MetadataReader reader,
     TypeDefinition def,
     ArrayBuilder<string> builder)
 {
     foreach (var typeParameterHandle in def.GetGenericParameters())
     {
         var typeParameter = reader.GetGenericParameter(typeParameterHandle);
         string fieldName;
         if (!GeneratedNames.TryParseAnonymousTypeParameterName(reader.GetString(typeParameter.Name), out fieldName))
         {
             return false;
         }
         builder.Add(fieldName);
     }
     return true;
 }
开发者ID:pheede,项目名称:roslyn,代码行数:17,代码来源:PEDeltaAssemblyBuilder.cs

示例10: 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

示例11: GetTokenForMethod

        private static MethodHandle GetTokenForMethod(MetadataReader metadataReader, string methodName)
        {
            Assert.NotNull(methodName);
            Assert.NotEmpty(methodName);

            foreach (var methodDef in metadataReader.MethodDefinitions)
            {
                string name = metadataReader.GetString(metadataReader.GetMethod(methodDef).Name);

                if (methodName.Equals(name))
                {
                    return methodDef;
                }
            }

            AssertEx.Fail("Unable to find method:" + methodName);
            return default(MethodHandle);
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:18,代码来源:EmitMetadataTestBase.cs

示例12: 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

示例13: 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

示例14: 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

示例15: GetAssemblyReferences

            private static AssemblyReference[] GetAssemblyReferences(MetadataReader reader)
            {
                var count = reader.GetTableRowCount(TableIndex.AssemblyRef);
                var references = new AssemblyReference[count];

                for (int i = 0; i < count; i++)
                {
                    var reference = reader.GetAssemblyReference(MetadataTokens.AssemblyReferenceHandle(i + 1));
                    references[i] = new AssemblyReference(reader.GetString(reference.Name), reference.Version);
                }

                return references.ToArray();
            }
开发者ID:roncain,项目名称:buildtools,代码行数:13,代码来源:VerifyClosure.cs


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