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;
}