本文整理汇总了C#中MetadataReader类的典型用法代码示例。如果您正苦于以下问题:C# MetadataReader类的具体用法?C# MetadataReader怎么用?C# MetadataReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetadataReader类属于命名空间,在下文中一共展示了MetadataReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例7: RuntimeGenericParameterType
internal RuntimeGenericParameterType(MetadataReader reader, GenericParameterHandle genericParameterHandle)
{
_reader = reader;
_genericParameterHandle = genericParameterHandle;
_genericParameter = _genericParameterHandle.GetGenericParameter(_reader);
_position = _genericParameter.Number;
}
示例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;
}
示例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()
);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}