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

IsCustomAttributeDefined() static private method

static private IsCustomAttributeDefined ( Module decoratedModule, int decoratedMetadataToken, RuntimeType attributeFilterType, bool mustBeInheritable ) : bool
decoratedModule Module
decoratedMetadataToken int
attributeFilterType RuntimeType
mustBeInheritable bool
return bool
        internal static bool IsCustomAttributeDefined(
            Module decoratedModule, int decoratedMetadataToken, RuntimeType attributeFilterType, bool mustBeInheritable)
        {
            if (decoratedModule.Assembly.ReflectionOnly)
                throw new InvalidOperationException(Environment.GetResourceString("Arg_ReflectionOnlyCA"));

            MetadataImport scope = decoratedModule.MetadataImport;
            CustomAttributeRecord[] car = CustomAttributeData.GetCustomAttributeRecords(decoratedModule, decoratedMetadataToken);
            RuntimeType attributeType;
            RuntimeMethodHandle ctor;
            bool ctorHasParameters, isVarArg;

            // Optimization for the case where attributes decorate entities in the same assembly in which case 
            // we can cache the successful APTCA check between the decorated and the declared assembly.
            Assembly lastAptcaOkAssembly = null;
            
            for (int i = 0; i < car.Length; i++)
            {           
                CustomAttributeRecord caRecord = car[i];
            
                if (FilterCustomAttributeRecord(caRecord, scope, ref lastAptcaOkAssembly, 
                    decoratedModule, decoratedMetadataToken, attributeFilterType, mustBeInheritable, null, null,
                    out attributeType, out ctor, out ctorHasParameters, out isVarArg))
                    return true;           
            }

            return false;
        }

Same methods

CustomAttribute::IsCustomAttributeDefined ( Module decoratedModule, int decoratedMetadataToken, RuntimeType attributeFilterType ) : bool

Usage Example

 internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
 {
     if (PseudoCustomAttribute.IsDefined(method, caType))
     {
         return(true);
     }
     if (CustomAttribute.IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType))
     {
         return(true);
     }
     if (!inherit)
     {
         return(false);
     }
     method = method.GetParentDefinition();
     while (method != null)
     {
         if (CustomAttribute.IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType, 0, inherit))
         {
             return(true);
         }
         method = method.GetParentDefinition();
     }
     return(false);
 }
All Usage Examples Of System.Reflection.CustomAttribute::IsCustomAttributeDefined