System.Reflection.CustomAttribute.AttributeUsageCheck C# (CSharp) Method

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
        private static bool AttributeUsageCheck(
            RuntimeType attributeType, bool mustBeInheritable, object[] attributes, IList derivedAttributes)
        {
            AttributeUsageAttribute attributeUsageAttribute = null;

            if (mustBeInheritable)
            {
                attributeUsageAttribute = CustomAttribute.GetAttributeUsage(attributeType);

                if (!attributeUsageAttribute.Inherited)
                    return false;
            }

            // Legacy: AllowMultiple ignored for none inheritable attributes

            if (derivedAttributes == null)
                return true;

            for (int i = 0; i < derivedAttributes.Count; i++)
            {
                if (derivedAttributes[i].GetType() == attributeType)
                {
                    if (attributeUsageAttribute == null)
                        attributeUsageAttribute = CustomAttribute.GetAttributeUsage(attributeType);

                    return attributeUsageAttribute.AllowMultiple;
                }
            }

            return true;
        }

Usage Example

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();
All Usage Examples Of System.Reflection.CustomAttribute::AttributeUsageCheck