• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MetadataReader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MetadataReader的典型用法代码示例。如果您正苦于以下问题:C# MetadataReader类的具体用法?C# MetadataReader怎么用?C# MetadataReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: CompareTypeReferenceToDefinition

        public static bool CompareTypeReferenceToDefinition(TypeReferenceHandle tr1, MetadataReader mr1, TypeDefinitionHandle td2, MetadataReader mr2)
        {
            // TODO! The correct implementation here is probably to call into the assembly binder, but that's not available due to layering.
            // For now, just implement comparison, which will be equivalent in all cases until we support loading multiple copies of the same assembly

            TypeReference trData1 = mr1.GetTypeReference(tr1);
            TypeDefinition tdData2 = mr2.GetTypeDefinition(td2);

            if (!trData1.TypeName.StringEquals(tdData2.Name.GetConstantStringValue(mr2).Value, mr1))
                return false;

            switch (trData1.ParentNamespaceOrType.HandleType)
            {
                case HandleType.TypeReference:
                    if (tdData2.EnclosingType.IsNull(mr2))
                        return false;

                    return CompareTypeReferenceToDefinition(trData1.ParentNamespaceOrType.ToTypeReferenceHandle(mr1), mr1, tdData2.EnclosingType, mr2);

                case HandleType.NamespaceReference:
                    return CompareNamespaceReferenceToDefinition(trData1.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr1), mr1, tdData2.NamespaceDefinition, mr2);

                default:
                    Debug.Assert(false);
                    throw new BadImageFormatException();
            }
        }
开发者ID:nattress,项目名称:corert,代码行数:27,代码来源:MetadataReaderHelpers.cs


示例2: RuntimeFatMethodParameterInfo

 private RuntimeFatMethodParameterInfo(MethodBase member, MethodHandle methodHandle, int position, ParameterHandle parameterHandle, ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
     : base(member, position, reflectionDomain, reader, typeHandle, typeContext)
 {
     _methodHandle = methodHandle;
     _parameterHandle = parameterHandle;
     _parameter = parameterHandle.GetParameter(reader);
 }
开发者ID:huamichaelchen,项目名称:corert,代码行数:7,代码来源:RuntimeFatMethodParameterInfo.cs


示例3: FindTestType

        public static TypeDefinitionHandle FindTestType(MetadataReader reader, Type type)
        {
            if (type.DeclaringType == null)
            {
                foreach (TypeDefinitionHandle handle in reader.TypeDefinitions)
                {
                    TypeDefinition definition = reader.GetTypeDefinition(handle);
                    if (reader.StringComparer.Equals(definition.Namespace, type.Namespace) &&
                        reader.StringComparer.Equals(definition.Name, type.Name))
                    {
                        return handle;
                    }
                }
            }
            else
            {
                TypeDefinitionHandle declaringHandle = FindTestType(reader, type.DeclaringType);
                TypeDefinition declaringDefinition = reader.GetTypeDefinition(declaringHandle);
                foreach (TypeDefinitionHandle handle in declaringDefinition.GetNestedTypes())
                {
                    TypeDefinition definition = reader.GetTypeDefinition(handle);
                    if (reader.StringComparer.Equals(definition.Name, type.Name))
                    {
                        return handle;
                    }
                }
            }

            Assert.True(false, "Cannot find test type:" + type);
            return default(TypeDefinitionHandle);
        }
开发者ID:jemmy655,项目名称:corefx,代码行数:31,代码来源:TestMetadataResolver.cs


示例4: GetFullName

        public static string GetFullName(this Handle handle, MetadataReader reader)
        {
            switch (handle.HandleType)
            {
                case HandleType.TypeDefinition:
                    return handle.ToTypeDefinitionHandle(reader).GetFullName(reader);
                case HandleType.TypeReference:
                    return handle.ToTypeReferenceHandle(reader).GetFullName(reader);

                case HandleType.NamespaceDefinition:
                    return handle.ToNamespaceDefinitionHandle(reader).GetFullName(reader);
                case HandleType.NamespaceReference:
                    return handle.ToNamespaceReferenceHandle(reader).GetFullName(reader);

                case HandleType.TypeSpecification:
                    return handle.ToTypeSpecificationHandle(reader).GetFullName(reader);
                case HandleType.TypeInstantiationSignature:
                    return handle.ToTypeInstantiationSignatureHandle(reader).GetFullName(reader);

                case HandleType.ArraySignature:
                    return handle.ToArraySignatureHandle(reader).GetFullName(reader);
                case HandleType.SZArraySignature:
                    return handle.ToSZArraySignatureHandle(reader).GetFullName(reader);

                case HandleType.PointerSignature:
                    return handle.ToPointerSignatureHandle(reader).GetFullName(reader);
                case HandleType.ByReferenceSignature:
                    return handle.ToByReferenceSignatureHandle(reader).GetFullName(reader);
            }
            return null;
        }
开发者ID:noahfalk,项目名称:corert,代码行数:31,代码来源:MetadataNameExtensions.cs


示例5: CodeReader

 public CodeReader(Section section, MetadataReader reader, Dictionary<uint, DumpedMethod> dumpedMethods = null)
     : base(section.Data)
 {
     this.code_section = section;
     this.reader = reader;
     this.dumpedMethods = dumpedMethods;
 }
开发者ID:bladecoding,项目名称:cecil,代码行数:7,代码来源:CodeReader.cs


示例6: CodeReader

		public CodeReader (MethodDefinition method, MetadataReader reader)
			: base (reader.image.Stream)
		{
			this.reader = reader;
			this.reader.context = method;
			this.Position = (int) reader.image.ResolveVirtualAddress ((uint) method.RVA);
		}
开发者ID:jeroldhaas,项目名称:ContinuousTests,代码行数:7,代码来源:CodeReader.cs


示例7: RuntimeGenericParameterType

 internal RuntimeGenericParameterType(MetadataReader reader, GenericParameterHandle genericParameterHandle)
 {
     _reader = reader;
     _genericParameterHandle = genericParameterHandle;
     _genericParameter = _genericParameterHandle.GetGenericParameter(_reader);
     _position = _genericParameter.Number;
 }
开发者ID:huamichaelchen,项目名称:corert,代码行数:7,代码来源:RuntimeGenericParameterType.cs


示例8: IsTypeDefRefOrSpecHandle

 public static bool IsTypeDefRefOrSpecHandle(this Handle handle, MetadataReader reader)
 {
     HandleType handleType = handle.HandleType;
     return handleType == HandleType.TypeDefinition ||
         handleType == HandleType.TypeReference ||
         handleType == HandleType.TypeSpecification;
 }
开发者ID:nattress,项目名称:corert,代码行数:7,代码来源:MetadataReaderExtensions.cs


示例9: CreateRuntimeAssemblyNameFromMetadata

        private static RuntimeAssemblyName CreateRuntimeAssemblyNameFromMetadata(
            MetadataReader reader,
            ConstantStringValueHandle name,
            ushort majorVersion,
            ushort minorVersion,
            ushort buildNumber,
            ushort revisionNumber,
            ConstantStringValueHandle culture,
            IEnumerable<byte> publicKeyOrToken,
            AssemblyFlags assemblyFlags)
        {
            AssemblyNameFlags assemblyNameFlags = AssemblyNameFlags.None;
            if (0 != (assemblyFlags & AssemblyFlags.PublicKey))
                assemblyNameFlags |= AssemblyNameFlags.PublicKey;
            if (0 != (assemblyFlags & AssemblyFlags.Retargetable))
                assemblyNameFlags |= AssemblyNameFlags.Retargetable;
            int contentType = ((int)assemblyFlags) & 0x00000E00;
            assemblyNameFlags |= (AssemblyNameFlags)contentType;

            ArrayBuilder<byte> keyOrTokenArrayBuilder = new ArrayBuilder<byte>();
            foreach (byte b in publicKeyOrToken)
                keyOrTokenArrayBuilder.Add(b);

            return new RuntimeAssemblyName(
                name.GetString(reader),
                new Version(majorVersion, minorVersion, buildNumber, revisionNumber),
                culture.GetStringOrNull(reader),
                assemblyNameFlags,
                keyOrTokenArrayBuilder.ToArray()
                );
        }
开发者ID:krytarowski,项目名称:corert,代码行数:31,代码来源:MetadataReaderExtensions.cs


示例10: GetDefaultValueIfAny

        public static bool GetDefaultValueIfAny(MemberType memberType, MetadataReader reader, Handle constantHandle, Type declaredType, IEnumerable<CustomAttributeData> customAttributes, out Object defaultValue)
        {
            if (!(constantHandle.IsNull(reader)))
            {
                defaultValue = ParseMetadataConstant(reader, constantHandle);
                if (declaredType.GetTypeInfo().IsEnum)
                    defaultValue = Enum.ToObject(declaredType, defaultValue);
                return true;
            }

            if (memberType != MemberType.Property)  // the attributes in question cannot be applied to properties.
            {
                // Legacy: If there are multiple default value attribute, the desktop picks one at random (and so do we...)
                foreach (CustomAttributeData cad in customAttributes)
                {
                    Type attributeType = cad.AttributeType;
                    TypeInfo attributeTypeInfo = attributeType.GetTypeInfo();
                    if (attributeTypeInfo.IsSubclassOf(typeof(CustomConstantAttribute)))
                    {
                        CustomConstantAttribute customConstantAttribute = (CustomConstantAttribute)(cad.Instantiate());
                        defaultValue = customConstantAttribute.Value;
                        return true;
                    }
                    if (attributeType.Equals(typeof(DecimalConstantAttribute)))
                    {
                        DecimalConstantAttribute decimalConstantAttribute = (DecimalConstantAttribute)(cad.Instantiate());
                        defaultValue = decimalConstantAttribute.Value;
                        return true;
                    }
                }
            }

            defaultValue = null;
            return false;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:35,代码来源:DefaultValueParser.cs


示例11: StringOrNullEquals

 public static bool StringOrNullEquals(this ConstantStringValueHandle handle, String valueOrNull, MetadataReader reader)
 {
     if (valueOrNull == null)
         return handle.IsNull(reader);
     if (handle.IsNull(reader))
         return false;
     return handle.StringEquals(valueOrNull, reader);
 }
开发者ID:nguerrera,项目名称:corert,代码行数:8,代码来源:MetadataReaderExtensions.cs


示例12: RuntimeMethodParameterInfo

 protected RuntimeMethodParameterInfo(MethodBase member, int position, ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
     : base(member, position)
 {
     _reflectionDomain = reflectionDomain;
     Reader = reader;
     _typeHandle = typeHandle;
     _typeContext = typeContext;
 }
开发者ID:huamichaelchen,项目名称:corert,代码行数:8,代码来源:RuntimeMethodParameterInfo.cs


示例13: Resolve

 //
 // Main routine to resolve a typeDef/Ref/Spec.
 //
 internal static RuntimeType Resolve(this ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeDefRefOrSpec, TypeContext typeContext)
 {
     Exception exception = null;
     RuntimeType runtimeType = reflectionDomain.TryResolve(reader, typeDefRefOrSpec, typeContext, ref exception);
     if (runtimeType == null)
         throw exception;
     return runtimeType;
 }
开发者ID:noahfalk,项目名称:corert,代码行数:11,代码来源:TypeResolver.cs


示例14: ReadMethodBody

		public static MethodBody ReadMethodBody (MethodDefinition method, MetadataReader metadata)
		{
			var reader = new CodeReader (method, metadata);
			reader.body = new MethodBody (method);

			reader.ReadMethodBody ();

			return reader.body;
		}
开发者ID:jeroldhaas,项目名称:ContinuousTests,代码行数:9,代码来源:CodeReader.cs


示例15: GetCustomAttributes

        private List<CustomAttributeHandle> GetCustomAttributes(MetadataReader reader, int token)
        {
            var attributes = new List<CustomAttributeHandle>();
            foreach (var caHandle in reader.GetCustomAttributes(new EntityHandle((uint)token)))
            {
                attributes.Add(caHandle);
            }

            return attributes;
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:10,代码来源:MetadataReaderTests.cs


示例16: NamespaceChain

        internal NamespaceChain(MetadataReader reader, NamespaceDefinitionHandle innerMostNamespaceHandle)
        {
            NamespaceDefinition currentNamespaceDefinition = innerMostNamespaceHandle.GetNamespaceDefinition(reader);
            ConstantStringValueHandle currentNameHandle = currentNamespaceDefinition.Name;
            Handle currentNamespaceHandle = innerMostNamespaceHandle.ToHandle(reader);
            LowLevelList<String> names = new LowLevelList<String>();
            for (; ;)
            {
                String name = currentNameHandle.GetStringOrNull(reader);
                names.Add(name);
                currentNamespaceHandle = currentNamespaceDefinition.ParentScopeOrNamespace;
                HandleType handleType = currentNamespaceHandle.HandleType;
                if (handleType == HandleType.ScopeDefinition)
                    break;
                if (handleType == HandleType.NamespaceDefinition)
                {
                    NamespaceDefinitionHandle nsHandle = currentNamespaceHandle.ToNamespaceDefinitionHandle(reader);
                    currentNamespaceDefinition = nsHandle.GetNamespaceDefinition(reader);
                    currentNameHandle = currentNamespaceDefinition.Name;
                    continue;
                }

                throw new BadImageFormatException(SR.Bif_InvalidMetadata);
            }

            DefiningScope = currentNamespaceHandle.ToScopeDefinitionHandle(reader);

            int count = names.Count;
            if (count == 0)
            {
                // Every namespace chain has to start with the root namespace.
                throw new BadImageFormatException();
            }
            else if (count == 1)
            {
                // The root namespace. For compat with the desktop, TypeInfo.NameSpaces returns null in this case.
                NameSpace = null;
            }
            else
            {
                // Namespace has at least one non-root component.
                StringBuilder sb = new StringBuilder();
                int idx = count - 1;
                while (idx-- != 0)
                {
                    String name = names[idx];
                    if (name == null)
                        throw new BadImageFormatException(); // null namespace fragment found in middle.
                    sb.Append(name);
                    if (idx != 0)
                        sb.Append('.');
                }
                NameSpace = sb.ToString();
            }
        }
开发者ID:huamichaelchen,项目名称:corert,代码行数:55,代码来源:NamespaceChain.cs


示例17: CreateMethodInvoker

 //
 // Creates the appropriate flavor of Invoker depending on the calling convention "shape" (static, instance or virtual.)
 //
 internal static MethodInvoker CreateMethodInvoker(MetadataReader reader, RuntimeTypeHandle declaringTypeHandle, MethodHandle methodHandle, MethodInvokeInfo methodInvokeInfo)
 {
     Method method = methodHandle.GetMethod(reader);
     MethodAttributes methodAttributes = method.Flags;
     if (0 != (methodAttributes & MethodAttributes.Static))
         return new StaticMethodInvoker(methodInvokeInfo);
     else if (methodInvokeInfo.VirtualResolveData != IntPtr.Zero)
         return new VirtualMethodInvoker(methodInvokeInfo, declaringTypeHandle);
     else
         return new InstanceMethodInvoker(methodInvokeInfo, declaringTypeHandle);
 }
开发者ID:noahfalk,项目名称:corert,代码行数:14,代码来源:MethodInvokerWithMethodInvokeInfo.cs


示例18: CreateMetadataReader

        /// <summary>
        /// Locate reflection blob in a given module and construct its metadata reader.
        /// </summary>
        /// <param name="moduleHandle">Module handle to register</param>
        unsafe void CreateMetadataReader(IntPtr moduleHandle)
        {
            uint* pBlob;
            uint cbBlob;

            if (RuntimeAugments.FindBlob(moduleHandle, (int)ReflectionMapBlob.EmbeddedMetadata, (IntPtr)(&pBlob), (IntPtr)(&cbBlob)))
            {
                MetadataReader reader = new MetadataReader((IntPtr)pBlob, (int)cbBlob);
                _moduleToMetadataReader.Add(moduleHandle, reader);
            }
        }
开发者ID:noahfalk,项目名称:corert,代码行数:15,代码来源:ExecutionEnvironmentImplementation.cs


示例19: TryResolve

 internal static RuntimeType TryResolve(this ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeDefRefOrSpec, TypeContext typeContext, ref Exception exception)
 {
     HandleType handleType = typeDefRefOrSpec.HandleType;
     if (handleType == HandleType.TypeDefinition)
         return reflectionDomain.ResolveTypeDefinition(reader, typeDefRefOrSpec.ToTypeDefinitionHandle(reader));
     else if (handleType == HandleType.TypeReference)
         return reflectionDomain.TryResolveTypeReference(reader, typeDefRefOrSpec.ToTypeReferenceHandle(reader), ref exception);
     else if (handleType == HandleType.TypeSpecification)
         return reflectionDomain.TryResolveTypeSignature(reader, typeDefRefOrSpec.ToTypeSpecificationHandle(reader), typeContext, ref exception);
     else
         throw new BadImageFormatException();  // Expected TypeRef, Def or Spec.
 }
开发者ID:noahfalk,项目名称:corert,代码行数:12,代码来源:TypeResolver.cs


示例20: NullableInstanceMethodInvoker

        public NullableInstanceMethodInvoker(MetadataReader reader, MethodHandle methodHandle, RuntimeTypeHandle nullableTypeHandle, MethodInvokeInfo methodInvokeInfo)
        {
            _id = NullableMethodId.None;
            _nullableTypeHandle = nullableTypeHandle;
            Method method = methodHandle.GetMethod(reader);
            if (MethodAttributes.Public == (method.Flags & MethodAttributes.MemberAccessMask))
            {
                // Note: Since we control the definition of Nullable<>, we're not checking signatures here.
                String name = method.Name.GetConstantStringValue(reader).Value;
                switch (name)
                {
                    case "GetType":
                        _id = NullableMethodId.GetType;
                        break;

                    case "ToString":
                        _id = NullableMethodId.ToString;
                        break;

                    case "Equals":
                        _id = NullableMethodId.Equals;
                        break;

                    case "GetHashCode":
                        _id = NullableMethodId.GetHashCode;
                        break;

                    case ".ctor":
                        _id = NullableMethodId.Ctor;
                        break;

                    case "get_HasValue":
                        _id = NullableMethodId.get_HasValue;
                        break;

                    case "get_Value":
                        _id = NullableMethodId.get_Value;
                        break;

                    case "GetValueOrDefault":
                        IEnumerator<ParameterTypeSignatureHandle> parameters = method.Signature.GetMethodSignature(reader).Parameters.GetEnumerator();
                        if (parameters.MoveNext())
                            _id = NullableMethodId.GetValueOrDefault_1;
                        else
                            _id = NullableMethodId.GetValueOrDefault_0;
                        break;

                    default:
                        break;
                }
            }
        }
开发者ID:noahfalk,项目名称:corert,代码行数:52,代码来源:NullableInstanceMethodInvoker.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MetadataReference类代码示例发布时间:2022-05-24
下一篇:
C# MetadataObject类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap