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

ParseAttributeUsageAttribute() private static method

private static ParseAttributeUsageAttribute ( ConstArray ca, AttributeTargets &targets, bool &inherited, bool &allowMultiple ) : void
ca ConstArray
targets AttributeTargets
inherited bool
allowMultiple bool
return void
        private static void ParseAttributeUsageAttribute(
            ConstArray ca, out AttributeTargets targets, out bool inherited, out bool allowMultiple)
        {
            int _targets;
            _ParseAttributeUsageAttribute(ca.Signature, ca.Length, out _targets, out inherited, out allowMultiple);
            targets = (AttributeTargets)_targets;
        }

Usage Example

        internal static AttributeUsageAttribute GetAttributeUsage(RuntimeType decoratedAttribute)
        {
            RuntimeModule  runtimeModule  = decoratedAttribute.GetRuntimeModule();
            MetadataImport metadataImport = runtimeModule.MetadataImport;

            CustomAttributeRecord[] customAttributeRecords  = CustomAttributeData.GetCustomAttributeRecords(runtimeModule, decoratedAttribute.MetadataToken);
            AttributeUsageAttribute attributeUsageAttribute = null;

            foreach (CustomAttributeRecord customAttributeRecord in customAttributeRecords)
            {
                RuntimeType runtimeType = runtimeModule.ResolveType(metadataImport.GetParentToken(customAttributeRecord.tkCtor), null, null) as RuntimeType;
                if (!(runtimeType != (RuntimeType)typeof(AttributeUsageAttribute)))
                {
                    if (attributeUsageAttribute != null)
                    {
                        throw new FormatException(string.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Format_AttributeUsage"), runtimeType));
                    }
                    AttributeTargets validOn;
                    bool             inherited;
                    bool             allowMultiple;
                    CustomAttribute.ParseAttributeUsageAttribute(customAttributeRecord.blob, out validOn, out inherited, out allowMultiple);
                    attributeUsageAttribute = new AttributeUsageAttribute(validOn, allowMultiple, inherited);
                }
            }
            if (attributeUsageAttribute == null)
            {
                return(AttributeUsageAttribute.Default);
            }
            return(attributeUsageAttribute);
        }