AttributeUsageCheck() private static method

private static AttributeUsageCheck ( RuntimeType attributeType, bool mustBeInheritable, object attributes, IList derivedAttributes ) : bool
attributeType RuntimeType
mustBeInheritable bool
attributes object
derivedAttributes IList
return bool
Exemplo n.º 1
0
        private static unsafe 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              = (IRuntimeMethodInfo)null;
            attributeType     = (RuntimeType)null;
            ctorHasParameters = false;
            isVarArg          = false;
            IntPtr num = (IntPtr)((void *)((IntPtr)(void *)caRecord.blob.Signature + caRecord.blob.Length));

            attributeType = decoratedModule.ResolveType(scope.GetParentToken((int)caRecord.tkCtor), (Type[])null, (Type[])null) as RuntimeType;
            if (!attributeFilterType.IsAssignableFrom((TypeInfo)attributeType) || !CustomAttribute.AttributeUsageCheck(attributeType, mustBeInheritable, attributes, derivedAttributes) || (attributeType.Attributes & TypeAttributes.WindowsRuntime) == TypeAttributes.WindowsRuntime)
            {
                return(false);
            }
            RuntimeAssembly targetAssembly = (RuntimeAssembly)attributeType.Assembly;
            RuntimeAssembly sourceAssembly = (RuntimeAssembly)decoratedModule.Assembly;

            if ((Assembly)targetAssembly != lastAptcaOkAssembly && !RuntimeAssembly.AptcaCheck(targetAssembly, sourceAssembly))
            {
                return(false);
            }
            lastAptcaOkAssembly = (Assembly)sourceAssembly;
            ConstArray methodSignature = scope.GetMethodSignature(caRecord.tkCtor);

            isVarArg          = ((uint)methodSignature[0] & 5U) > 0U;
            ctorHasParameters = (uint)methodSignature[1] > 0U;
            RuntimeTypeHandle runtimeTypeHandle1;

            if (ctorHasParameters)
            {
                ctor = ModuleHandle.ResolveMethodHandleInternal(decoratedModule.GetNativeHandle(), (int)caRecord.tkCtor);
            }
            else
            {
                // ISSUE: explicit reference operation
                // ISSUE: variable of a reference type
                IRuntimeMethodInfo& local = @ctor;
                runtimeTypeHandle1 = attributeType.GetTypeHandleInternal();
                IRuntimeMethodInfo defaultConstructor = runtimeTypeHandle1.GetDefaultConstructor();
        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 signature = caRecord.blob.Signature;
            IntPtr intPtr    = (IntPtr)((void *)((byte *)((void *)signature) + caRecord.blob.Length));

            attributeType = (decoratedModule.ResolveType(scope.GetParentToken(caRecord.tkCtor), null, null) as RuntimeType);
            if (!attributeFilterType.IsAssignableFrom(attributeType))
            {
                return(false);
            }
            if (!CustomAttribute.AttributeUsageCheck(attributeType, mustBeInheritable, attributes, derivedAttributes))
            {
                return(false);
            }
            if ((attributeType.Attributes & TypeAttributes.WindowsRuntime) == TypeAttributes.WindowsRuntime)
            {
                return(false);
            }
            RuntimeAssembly runtimeAssembly  = (RuntimeAssembly)attributeType.Assembly;
            RuntimeAssembly runtimeAssembly2 = (RuntimeAssembly)decoratedModule.Assembly;

            if (runtimeAssembly != lastAptcaOkAssembly && !RuntimeAssembly.AptcaCheck(runtimeAssembly, runtimeAssembly2))
            {
                return(false);
            }
            lastAptcaOkAssembly = runtimeAssembly2;
            ConstArray methodSignature = scope.GetMethodSignature(caRecord.tkCtor);

            isVarArg          = ((methodSignature[0] & 5) > 0);
            ctorHasParameters = (methodSignature[1] > 0);
            if (ctorHasParameters)
            {
                ctor = ModuleHandle.ResolveMethodHandleInternal(decoratedModule.GetNativeHandle(), caRecord.tkCtor);
            }
            else
            {
                ctor = attributeType.GetTypeHandleInternal().GetDefaultConstructor();
                if (ctor == null && !attributeType.IsValueType)
                {
                    throw new MissingMethodException(".ctor");
                }
            }
            MetadataToken token = default(MetadataToken);

            if (decoratedToken.IsParamDef)
            {
                token = new MetadataToken(scope.GetParentToken(decoratedToken));
                token = new MetadataToken(scope.GetParentToken(token));
            }
            else if (decoratedToken.IsMethodDef || decoratedToken.IsProperty || decoratedToken.IsEvent || decoratedToken.IsFieldDef)
            {
                token = new MetadataToken(scope.GetParentToken(decoratedToken));
            }
            else if (decoratedToken.IsTypeDef)
            {
                token = decoratedToken;
            }
            else if (decoratedToken.IsGenericPar)
            {
                token = new MetadataToken(scope.GetParentToken(decoratedToken));
                if (token.IsMethodDef)
                {
                    token = new MetadataToken(scope.GetParentToken(token));
                }
            }
            RuntimeTypeHandle sourceTypeHandle = token.IsTypeDef ? decoratedModule.ModuleHandle.ResolveTypeHandle(token) : default(RuntimeTypeHandle);

            return(RuntimeMethodHandle.IsCAVisibleFromDecoratedType(attributeType.TypeHandle, ctor, sourceTypeHandle, decoratedModule));
        }