本文整理匯總了C#中System.RuntimeMethodHandle.IsVisibleFromType方法的典型用法代碼示例。如果您正苦於以下問題:C# RuntimeMethodHandle.IsVisibleFromType方法的具體用法?C# RuntimeMethodHandle.IsVisibleFromType怎麽用?C# RuntimeMethodHandle.IsVisibleFromType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.RuntimeMethodHandle
的用法示例。
在下文中一共展示了RuntimeMethodHandle.IsVisibleFromType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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)));
}
示例2: 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;
}