本文整理汇总了C#中System.Reflection.MetadataToken类的典型用法代码示例。如果您正苦于以下问题:C# MetadataToken类的具体用法?C# MetadataToken怎么用?C# MetadataToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetadataToken类属于System.Reflection命名空间,在下文中一共展示了MetadataToken类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ResolveSignature
[System.Security.SecuritySafeCritical] // auto-generated
public override byte[] ResolveSignature(int metadataToken)
{
MetadataToken tk = new MetadataToken(metadataToken);
if (!MetadataImport.IsValidToken(tk))
throw new ArgumentOutOfRangeException(nameof(metadataToken),
Environment.GetResourceString("Argument_InvalidToken", tk, this));
if (!tk.IsMemberRef && !tk.IsMethodDef && !tk.IsTypeSpec && !tk.IsSignature && !tk.IsFieldDef)
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidToken", tk, this),
nameof(metadataToken));
ConstArray signature;
if (tk.IsMemberRef)
signature = MetadataImport.GetMemberRefProps(metadataToken);
else
signature = MetadataImport.GetSignatureFromToken(metadataToken);
byte[] sig = new byte[signature.Length];
for (int i = 0; i < signature.Length; i++)
sig[i] = signature[i];
return sig;
}
开发者ID:AtsushiKan,项目名称:coreclr,代码行数:26,代码来源:Module.cs
示例2: HasAttribute
// TODO (tomat): disable the warning temporarily until we move this code to the metadata reader
#pragma warning disable 618
private bool HasAttribute(MetadataToken token, string namespaceName, string typeName)
{
foreach (var caHandle in peFileReader.GetCustomAttributes(token))
{
StringHandle namespaceHandle, nameHandle;
if (peFileReader.GetCustomAttribute(caHandle).GetFullTypeName(out namespaceHandle, out nameHandle) &&
peFileReader.StringStream.CheckForText(namespaceHandle, namespaceName) &&
peFileReader.StringStream.CheckForText(nameHandle, typeName))
{
return true;
}
}
return false;
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:17,代码来源:WinMDModule.cs
示例3: FilterCustomAttributeRecord
[System.Security.SecurityCritical] // auto-generated
private unsafe static bool FilterCustomAttributeRecord(
CustomAttributeRecord caRecord,
MetadataImport scope,
ref Assembly lastAptcaOkAssembly,
RuntimeModule decoratedModule,
MetadataToken decoratedToken,
RuntimeType attributeFilterType,
bool mustBeInheritable,
object[] attributes,
IList derivedAttributes,
out RuntimeType attributeType,
out IRuntimeMethodInfo ctor,
out bool ctorHasParameters,
out bool isVarArg)
{
ctor = null;
attributeType = null;
ctorHasParameters = false;
isVarArg = false;
IntPtr blobStart = caRecord.blob.Signature;
IntPtr blobEnd = (IntPtr)((byte*)blobStart + caRecord.blob.Length);
#if FEATURE_LEGACYNETCF
if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8) {
try
{
// Resolve attribute type from ctor parent token found in decorated decoratedModule scope
attributeType = decoratedModule.ResolveType(scope.GetParentToken(caRecord.tkCtor), null, null) as RuntimeType;
}
catch(Exception)
{
return false;
}
}
else
#endif
// Resolve attribute type from ctor parent token found in decorated decoratedModule scope
attributeType = decoratedModule.ResolveType(scope.GetParentToken(caRecord.tkCtor), null, null) as RuntimeType;
// Test attribute type against user provided attribute type filter
if (!(attributeFilterType.IsAssignableFrom(attributeType)))
return false;
// Ensure if attribute type must be inheritable that it is inhertiable
// Ensure that to consider a duplicate attribute type AllowMultiple is true
if (!AttributeUsageCheck(attributeType, mustBeInheritable, attributes, derivedAttributes))
return false;
// Windows Runtime attributes aren't real types - they exist to be read as metadata only, and as such
// should be filtered out of the GetCustomAttributes path.
if ((attributeType.Attributes & TypeAttributes.WindowsRuntime) == TypeAttributes.WindowsRuntime)
{
return false;
}
#if FEATURE_APTCA
// APTCA checks
RuntimeAssembly attributeAssembly = (RuntimeAssembly)attributeType.Assembly;
RuntimeAssembly decoratedModuleAssembly = (RuntimeAssembly)decoratedModule.Assembly;
if (attributeAssembly != lastAptcaOkAssembly &&
!RuntimeAssembly.AptcaCheck(attributeAssembly, decoratedModuleAssembly))
return false;
// Cache last successful APTCA check (optimization)
lastAptcaOkAssembly = decoratedModuleAssembly;
#endif // FEATURE_APTCA
// Resolve the attribute ctor
ConstArray ctorSig = scope.GetMethodSignature(caRecord.tkCtor);
isVarArg = (ctorSig[0] & 0x05) != 0;
ctorHasParameters = ctorSig[1] != 0;
if (ctorHasParameters)
{
// Resolve method ctor token found in decorated decoratedModule scope
ctor = ModuleHandle.ResolveMethodHandleInternal(decoratedModule.GetNativeHandle(), caRecord.tkCtor);
}
else
{
// Resolve method ctor token from decorated decoratedModule scope
ctor = attributeType.GetTypeHandleInternal().GetDefaultConstructor();
if (ctor == null && !attributeType.IsValueType)
throw new MissingMethodException(".ctor");
}
// Visibility checks
MetadataToken tkParent = new MetadataToken();
if (decoratedToken.IsParamDef)
{
tkParent = new MetadataToken(scope.GetParentToken(decoratedToken));
tkParent = new MetadataToken(scope.GetParentToken(tkParent));
}
else if (decoratedToken.IsMethodDef || decoratedToken.IsProperty || decoratedToken.IsEvent || decoratedToken.IsFieldDef)
{
//.........这里部分代码省略.........
开发者ID:enavro,项目名称:coreclr,代码行数:101,代码来源:CustomAttribute.cs
示例4: MethodSymbols
public MethodSymbols(MetadataToken methodToken)
{
this.method_token = methodToken;
}
开发者ID:terurou,项目名称:cecil,代码行数:4,代码来源:Symbols.cs
示例5: GetDefaultValue
internal object GetDefaultValue(MetadataToken token) {
ElementType type;
int constantRid = ConstantTable.GetConstantRowId(token);
if (constantRid == 0) {
return Missing.Value;
}
uint blob = ConstantTable.GetValue(constantRid, out type);
return GetBlobValue(blob, type);
}
开发者ID:follesoe,项目名称:ironruby,代码行数:9,代码来源:MetadataImport.cs
示例6: ResolveField
[System.Security.SecuritySafeCritical] // auto-generated
public override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
{
MetadataToken tk = new MetadataToken(metadataToken);
if (!MetadataImport.IsValidToken(tk))
throw new ArgumentOutOfRangeException(nameof(metadataToken),
Environment.GetResourceString("Argument_InvalidToken", tk, this));
RuntimeTypeHandle[] typeArgs = ConvertToTypeHandleArray(genericTypeArguments);
RuntimeTypeHandle[] methodArgs = ConvertToTypeHandleArray(genericMethodArguments);
try
{
IRuntimeFieldInfo fieldHandle = null;
if (!tk.IsFieldDef)
{
if (!tk.IsMemberRef)
throw new ArgumentException(Environment.GetResourceString("Argument_ResolveField", tk, this),
nameof(metadataToken));
unsafe
{
ConstArray sig = MetadataImport.GetMemberRefProps(tk);
if (*(MdSigCallingConvention*)sig.Signature.ToPointer() != MdSigCallingConvention.Field)
throw new ArgumentException(Environment.GetResourceString("Argument_ResolveField", tk, this),
nameof(metadataToken));
}
fieldHandle = ModuleHandle.ResolveFieldHandleInternal(GetNativeHandle(), tk, typeArgs, methodArgs);
}
fieldHandle = ModuleHandle.ResolveFieldHandleInternal(GetNativeHandle(), metadataToken, typeArgs, methodArgs);
RuntimeType declaringType = RuntimeFieldHandle.GetApproxDeclaringType(fieldHandle.Value);
if (declaringType.IsGenericType || declaringType.IsArray)
{
int tkDeclaringType = ModuleHandle.GetMetadataImport(GetNativeHandle()).GetParentToken(metadataToken);
declaringType = (RuntimeType)ResolveType(tkDeclaringType, genericTypeArguments, genericMethodArguments);
}
return System.RuntimeType.GetFieldInfo(declaringType, fieldHandle);
}
catch(MissingFieldException)
{
return ResolveLiteralField(tk, genericTypeArguments, genericMethodArguments);
}
catch (BadImageFormatException e)
{
throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), e);
}
}
开发者ID:AtsushiKan,项目名称:coreclr,代码行数:54,代码来源:Module.cs
示例7: ResolveMember
[System.Security.SecuritySafeCritical] // auto-generated
public override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
{
MetadataToken tk = new MetadataToken(metadataToken);
if (tk.IsProperty)
throw new ArgumentException(Environment.GetResourceString("InvalidOperation_PropertyInfoNotAvailable"));
if (tk.IsEvent)
throw new ArgumentException(Environment.GetResourceString("InvalidOperation_EventInfoNotAvailable"));
if (tk.IsMethodSpec || tk.IsMethodDef)
return ResolveMethod(metadataToken, genericTypeArguments, genericMethodArguments);
if (tk.IsFieldDef)
return ResolveField(metadataToken, genericTypeArguments, genericMethodArguments);
if (tk.IsTypeRef || tk.IsTypeDef || tk.IsTypeSpec)
return ResolveType(metadataToken, genericTypeArguments, genericMethodArguments);
if (tk.IsMemberRef)
{
if (!MetadataImport.IsValidToken(tk))
throw new ArgumentOutOfRangeException(nameof(metadataToken),
Environment.GetResourceString("Argument_InvalidToken", tk, this));
ConstArray sig = MetadataImport.GetMemberRefProps(tk);
unsafe
{
if (*(MdSigCallingConvention*)sig.Signature.ToPointer() == MdSigCallingConvention.Field)
{
return ResolveField(tk, genericTypeArguments, genericMethodArguments);
}
else
{
return ResolveMethod(tk, genericTypeArguments, genericMethodArguments);
}
}
}
throw new ArgumentException(Environment.GetResourceString("Argument_ResolveMember", tk, this),
nameof(metadataToken));
}
开发者ID:AtsushiKan,项目名称:coreclr,代码行数:44,代码来源:Module.cs
示例8: FindCustomAttributesForToken
internal int FindCustomAttributesForToken(MetadataToken token, out int customAttributeCount)
{
return BinarySearchTag(HasCustomAttributeTag.ConvertToTag(token), out customAttributeCount);
}
开发者ID:TerabyteX,项目名称:main,代码行数:4,代码来源:MetadataTableImplementations.cs
示例9: FindSecurityAttributesForToken
internal int FindSecurityAttributesForToken(MetadataToken token, out int securityAttributeCount)
{
uint searchCodedTag = HasDeclSecurityTag.ConvertToTag(token);
return BinarySearchTag(searchCodedTag, out securityAttributeCount);
}
开发者ID:TerabyteX,项目名称:main,代码行数:5,代码来源:MetadataTableImplementations.cs
示例10: GetFieldMarshalRowId
internal int GetFieldMarshalRowId(MetadataToken token)
{
int foundRowNumber = Table.BinarySearchReference(
NumberOfRows,
RowSize,
ParentOffset,
HasFieldMarshalTag.ConvertToTag(token),
IsHasFieldMarshalRefSizeSmall
);
return foundRowNumber + 1;
}
开发者ID:TerabyteX,项目名称:main,代码行数:11,代码来源:MetadataTableImplementations.cs
示例11: GetConstantRowId
internal int GetConstantRowId(MetadataToken parentToken)
{
int foundRowNumber = Table.BinarySearchReference(
NumberOfRows,
RowSize,
ParentOffset,
HasConstantTag.ConvertToTag(parentToken),
IsHasConstantRefSizeSmall
);
return foundRowNumber + 1;
}
开发者ID:TerabyteX,项目名称:main,代码行数:11,代码来源:MetadataTableImplementations.cs
示例12: IsValidToken
public bool IsValidToken(MetadataToken token)
{
return m_import.IsValidToken(token);
}
开发者ID:TerabyteX,项目名称:main,代码行数:4,代码来源:MetadataTables.CCI.cs
示例13: GetTypeDefProps
public override void GetTypeDefProps(
TypeHandle typeDef,
out string name,
out string namespaceName,
out TypeAttributes flags,
out MetadataToken extends)
{
base.GetTypeDefProps(typeDef,
out name,
out namespaceName,
out flags,
out extends);
TypeDefTreatment treatment =
GetTypeDefTreatment(typeDef, flags, name, namespaceName, extends);
switch (treatment & TypeDefTreatment.TreatmentMask)
{
case TypeDefTreatment.None:
break;
case TypeDefTreatment.NormalNonAttribute:
flags |= TypeAttributes.WindowsRuntime | TypeAttributes.Import;
break;
case TypeDefTreatment.NormalAttribute:
flags |= TypeAttributes.WindowsRuntime | TypeAttributes.Sealed;
break;
case TypeDefTreatment.UnmangleWinRTName:
name = name.Substring(clrPrefix.Length);
flags |= TypeAttributes.Public;
break;
case TypeDefTreatment.PrefixWinRTName:
name = winRtPrefix + name;
flags &= TypeAttributes.Public;
flags |= TypeAttributes.Import;
break;
case TypeDefTreatment.RedirectedToCLRType:
flags &= ~TypeAttributes.Public;
flags |= TypeAttributes.Import;
break;
case TypeDefTreatment.RedirectedToCLRAttribute:
flags &= ~TypeAttributes.Public;
break;
}
if (treatment.HasFlag(TypeDefTreatment.MarkAbstractFlag))
{
flags |= TypeAttributes.Abstract;
}
if (treatment.HasFlag(TypeDefTreatment.MarkInternalFlag))
{
flags &= ~TypeAttributes.Public;
}
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:60,代码来源:WinMDModule.cs
示例14: GetTypeRefProps
public override void GetTypeRefProps(
TypeReferenceHandle typeRef,
out string name,
out string @namespace,
out MetadataToken resolutionScope)
{
base.GetTypeRefProps(typeRef, out name, out @namespace, out resolutionScope);
// TODO (tomat): disable the warning temporarily until we move this code to the metadata reader
#pragma warning disable 618 // obsolete warning reported when RowIds are used
uint assemblyRefOffset;
string clrName, clrNamespace;
if (WinRTProjectedTypes.ResolveWinRTTypeReference(name, @namespace, out clrName, out clrNamespace, out assemblyRefOffset))
{
name = clrName;
@namespace = clrNamespace;
uint assemblyRefRid = this.winMdStartIndex + assemblyRefOffset + 1;
resolutionScope = AssemblyReferenceHandle.FromRowId(assemblyRefRid);
}
else if (GetTypeRefTreatment(typeRef) != TypeRefTreatment.None)
{
uint assemblyRefRid = this.winMdStartIndex + (uint)WinMdAssembliesOffsets.SystemRuntime + 1;
resolutionScope = AssemblyReferenceHandle.FromRowId(assemblyRefRid);
}
#pragma warning restore 618 // obsolete warning reported when RowIds are used
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:26,代码来源:WinMDModule.cs
示例15: ResolveMethod
[System.Security.SecuritySafeCritical] // auto-generated
public override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
{
MetadataToken tk = new MetadataToken(metadataToken);
if (!MetadataImport.IsValidToken(tk))
throw new ArgumentOutOfRangeException(nameof(metadataToken),
Environment.GetResourceString("Argument_InvalidToken", tk, this));
RuntimeTypeHandle[] typeArgs = ConvertToTypeHandleArray(genericTypeArguments);
RuntimeTypeHandle[] methodArgs = ConvertToTypeHandleArray(genericMethodArguments);
try
{
if (!tk.IsMethodDef && !tk.IsMethodSpec)
{
if (!tk.IsMemberRef)
throw new ArgumentException(Environment.GetResourceString("Argument_ResolveMethod", tk, this),
nameof(metadataToken));
unsafe
{
ConstArray sig = MetadataImport.GetMemberRefProps(tk);
if (*(MdSigCallingConvention*)sig.Signature.ToPointer() == MdSigCallingConvention.Field)
throw new ArgumentException(Environment.GetResourceString("Argument_ResolveMethod", tk, this),
nameof(metadataToken));
}
}
IRuntimeMethodInfo methodHandle = ModuleHandle.ResolveMethodHandleInternal(GetNativeHandle(), tk, typeArgs, methodArgs);
Type declaringType = RuntimeMethodHandle.GetDeclaringType(methodHandle);
if (declaringType.IsGenericType || declaringType.IsArray)
{
MetadataToken tkDeclaringType = new MetadataToken(MetadataImport.GetParentToken(tk));
if (tk.IsMethodSpec)
tkDeclaringType = new MetadataToken(MetadataImport.GetParentToken(tkDeclaringType));
declaringType = ResolveType(tkDeclaringType, genericTypeArguments, genericMethodArguments);
}
return System.RuntimeType.GetMethodBase(declaringType as RuntimeType, methodHandle);
}
catch (BadImageFormatException e)
{
throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), e);
}
}
开发者ID:AtsushiKan,项目名称:coreclr,代码行数:50,代码来源:Module.cs
示例16: FilterCustomAttributeRecord
internal unsafe static bool FilterCustomAttributeRecord(
CustomAttributeRecord caRecord, MetadataImport scope, ref Assembly lastAptcaOkAssembly,
Module decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, bool mustBeInheritable,
object[] attributes, IList derivedAttributes,
out RuntimeType attributeType, out RuntimeMethodHandle ctor, out bool ctorHasParameters, out bool isVarArg)
{
ctor = new RuntimeMethodHandle();
attributeType = null;
ctorHasParameters = false;
isVarArg = false;
IntPtr blobStart = caRecord.blob.Signature;
IntPtr blobEnd = (IntPtr)((byte*)blobStart + caRecord.blob.Length);
// Resolve attribute type from ctor parent token found in decorated decoratedModule scope
attributeType = decoratedModule.ResolveType(scope.GetParentToken(caRecord.tkCtor), null, null) as RuntimeType;
// Test attribute type against user provided attribute type filter
if (!(attributeFilterType.IsAssignableFrom(attributeType)))
return false;
if (!AttributeUsageCheck(attributeType, mustBeInheritable, attributes, derivedAttributes))
return false;
// APTCA checks
if (attributeType.Assembly != lastAptcaOkAssembly &&
!attributeType.Assembly.AptcaCheck(decoratedModule.Assembly))
return false;
// Cache last successful APTCA check (optimization)
lastAptcaOkAssembly = decoratedModule.Assembly;
// Resolve the attribute ctor
ConstArray ctorSig = scope.GetMethodSignature(caRecord.tkCtor);
isVarArg = (ctorSig[0] & 0x05) != 0;
ctorHasParameters = ctorSig[1] != 0;
if (ctorHasParameters)
{
// Resolve method ctor token found in decorated decoratedModule scope
ctor = decoratedModule.ModuleHandle.ResolveMethodHandle(caRecord.tkCtor);
}
else
{
// Resolve method ctor token from decorated decoratedModule scope
ctor = attributeType.GetTypeHandleInternal().GetDefaultConstructor();
if (ctor.IsNullHandle() && !attributeType.IsValueType)
throw new MissingMethodException(".ctor");
}
// Visibility checks
if (ctor.IsNullHandle())
{
if (!attributeType.IsVisible && !attributeType.TypeHandle.IsVisibleFromModule(decoratedModule.ModuleHandle))
return false;
return true;
}
if (ctor.IsVisibleFromModule(decoratedModule))
return true;
MetadataToken tkParent = new MetadataToken();
if (decoratedToken.IsParamDef)
{
tkParent = new MetadataToken(scope.GetParentToken(decoratedToken));
tkParent = new MetadataToken(scope.GetParentToken(tkParent));
}
else if (decoratedToken.IsMethodDef || decoratedToken.IsProperty || decoratedToken.IsEvent || decoratedToken.IsFieldDef)
{
tkParent = new MetadataToken(scope.GetParentToken(decoratedToken));
}
else if (decoratedToken.IsTypeDef)
{
tkParent = decoratedToken;
}
if (tkParent.IsTypeDef)
return ctor.IsVisibleFromType(decoratedModule.ModuleHandle.ResolveTypeHandle(tkParent));
return false;
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:84,代码来源:customattribute.cs
示例17: ResolveLiteralField
[System.Security.SecurityCritical] // auto-generated
private FieldInfo ResolveLiteralField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
{
MetadataToken tk = new MetadataToken(metadataToken);
if (!MetadataImport.IsValidToken(tk) || !tk.IsFieldDef)
throw new ArgumentOutOfRangeException(nameof(metadataToken),
String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Argument_InvalidToken", tk, this)));
int tkDeclaringType;
string fieldName;
fieldName = MetadataImport.GetName(tk).ToString();
tkDeclaringType = MetadataImport.GetParentToken(tk);
Type declaringType = ResolveType(tkDeclaringType, genericTypeArguments, genericMethodArguments);
declaringType.GetFields();
try
{
return declaringType.GetField(fieldName,
BindingFlags.Static | BindingFlags.Instance |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.DeclaredOnly);
}
catch
{
throw new ArgumentException(Environment.GetResourceString("Argument_ResolveField", tk, this), nameof(metadataToken));
}
}
开发者ID:AtsushiKan,项目名称:coreclr,代码行数:31,代码来源:Module.cs
示例18: FilterCustomAttributeRecord
internal static unsafe bool FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, ref Assembly lastAptcaOkAssembly, Module decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, bool mustBeInheritable, object[] attributes, IList derivedAttributes, out RuntimeType attributeType, out RuntimeMethodHandle ctor, out bool ctorHasParameters, out bool isVarArg)
{
ctor = new RuntimeMethodHandle();
attributeType = null;
ctorHasParameters = false;
isVarArg = false;
IntPtr ptr1 = (IntPtr) (((void*) caRecord.blob.Signature) + caRecord.blob.Length);
attributeType = decoratedModule.ResolveType(scope.GetParentToken((int) caRecord.tkCtor), null, null) as RuntimeType;
if (!attributeFilterType.IsAssignableFrom(attributeType))
{
return false;
}
if (!AttributeUsageCheck(attributeType, mustBeInheritable, attributes, derivedAttributes))
{
return false;
}
if ((attributeType.Assembly != lastAptcaOkAssembly) && !attributeType.Assembly.AptcaCheck(decoratedModule.Assembly))
{
return false;
}
lastAptcaOkAssembly = decoratedModule.Assembly;
ConstArray methodSignature = scope.GetMethodSignature(caRecord.tkCtor);
isVarArg = (methodSignature[0] & 5) != 0;
ctorHasParameters = methodSignature[1] != 0;
if (ctorHasParameters)
{
ctor = decoratedModule.ModuleHandle.ResolveMethodHandle((int) caRecord.tkCtor);
}
else
{
ctor = attributeType.GetTypeHandleInternal().GetDefaultConstructor();
if (ctor.IsNullHandle() && !attributeType.IsValueType)
{
throw new MissingMethodException(".ctor");
}
}
if (ctor.IsNullHandle())
{
if (!attributeType.IsVisible && !attributeType.TypeHandle.IsVisibleFromModule(decoratedModule.ModuleHandle))
{
return false;
}
return true;
}
if (ctor.IsVisibleFromModule(decoratedModule))
{
return true;
}
MetadataToken token = new MetadataToken();
if (decoratedToken.IsParamDef)
{
token = new MetadataToken(scope.GetParentToken((int) decoratedToken));
token = new MetadataToken(scope.GetParentToken((int) token));
}
else if ((decoratedToken.IsMethodDef || decoratedToken.IsProperty) || (decoratedToken.IsEvent || decoratedToken.IsFieldDef))
{
token = new MetadataToken(scope.GetParentToken((int) decoratedToken));
}
else if (decoratedToken.IsTypeDef)
{
token = decoratedToken;
}
return (token.IsTypeDef && ctor.IsVisibleFromType(decoratedModule.ModuleHandle.ResolveTypeHandle((int) token)));
}
开发者ID:randomize,项目名称:VimConfig,代码行数:64,代码来源:CustomAttribute.cs
示例19: ResolveType
[System.Security.SecuritySafeCritical] // auto-generated
public override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
{
MetadataToken tk = new MetadataToken(metadataToken);
if (tk.IsGlobalTypeDefToken)
throw new ArgumentException(Environment.GetResourceString("Argument_ResolveModuleType", tk), nameof(metadataToken));
if (!MetadataImport.IsValidToken(tk))
throw new ArgumentOutOfRangeException(nameof(metadataToken),
Environment.GetResourceString("Argument_InvalidToken", tk, this));
if (!tk.IsTypeDef && !tk.IsTypeSpec && !tk.IsTypeRef)
throw new ArgumentException(Environment.GetResourceString("Argument_ResolveType", tk, this), nameof(metadataToken));
RuntimeTypeHandle[] typeArgs = ConvertToTypeHandleArray(genericTypeArguments);
RuntimeTypeHandle[] methodArgs = ConvertToTypeHandleArray(genericMethodArguments);
try
{
Type t = GetModuleHandle().ResolveTypeHandle(metadataToken, typeArgs, methodArgs).GetRuntimeType();
if (t == null)
throw new ArgumentException(Environment.GetResourceString("Argument_ResolveType", tk, this), nameof(metadataToken));
return t;
}
catch (BadImageFormatException e)
{
throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), e);
}
}
开发者ID:AtsushiKan,项目名称:coreclr,代码行数:32,代码来源:Module.cs
示例20: ResolveField
public FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
{
MetadataToken tk = new MetadataToken(metadataToken);
if (!MetadataImport.IsValidToken(tk))
throw new ArgumentOutOfRangeException("metadataToken",
String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidToken", tk, this)));
RuntimeTypeHandle[] typeArgs = ConvertToTypeHandleArray(genericTypeArguments);
RuntimeTypeHandle[] methodArgs = ConvertToTypeHandleArray(genericMethodArguments);
try
{
RuntimeFieldHandle fieldHandle = new RuntimeFieldHandle();
if (!tk.IsFieldDef)
{
if (!tk.IsMemberRef)
throw new ArgumentException("metadataToken",
String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_ResolveField"), tk, this));
unsafe
{
ConstArray sig = MetadataImport.GetMemberRefProps(tk);
if (*(CorCallingConvention*)sig.Signature.ToPointer() != CorCallingConvention.Field)
throw new ArgumentException("metadataToken",
String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_ResolveField"), tk, this));
}
fieldHandle = GetModuleHandle().ResolveFieldHandle(tk, typeArgs, methodArgs);
}
fieldHandle = GetModuleHandle().ResolveFieldHandle(metadataToken, typeArgs, methodArgs);
Type declaringType = fieldHandle.GetApproxDeclaringType().GetRuntimeType();
if (declaringType.IsGenericType || declaringType.IsArray)
{
int tkDeclaringType = GetModuleHandle().GetMetadataImport().GetParentToken(metadataToken);
declaringType = ResolveType(tkDeclaringType, genericTypeArguments, genericMethodArguments);
}
return System.RuntimeType.GetFieldInfo(declaringType.GetTypeHandleInternal(), fieldHandle);
}
catch(MissingFieldException)
{
return ResolveLiteralField(tk, genericTypeArguments, genericMethodArguments);
}
catch (BadImageFormatException e)
{
throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), e);
}
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:53,代码来源:module.cs
注:本文中的System.Reflection.MetadataToken类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论