private void InitializeCustomAttributes(SetCustomAttributeDelegate setCustomAttribute, CustomAttributeCollection attributes)
        {
            foreach (CustomAttribute attribute in attributes)
            {
                attribute.Resolve();

                ConstructorInfo constructor     = ResolveConstructor(attribute.Constructor);
                object[]        constructorArgs = CollectionUtils.ToArray <object>(attribute.ConstructorParameters);
                Type            attributeType   = constructor.ReflectedType;

                PropertyInfo[] namedProperties = new PropertyInfo[attribute.Properties.Count];
                object[]       propertyValues  = new object[attribute.Properties.Count];
                int            i = 0;
                foreach (DictionaryEntry entry in attribute.Properties)
                {
                    namedProperties[i] = GetProperty(attributeType, (string)entry.Key);
                    propertyValues[i]  = entry.Value;
                    i += 1;
                }

                FieldInfo[] namedFields = new FieldInfo[attribute.Fields.Count];
                object[]    fieldValues = new object[attribute.Fields.Count];
                i = 0;
                foreach (DictionaryEntry entry in attribute.Fields)
                {
                    namedFields[i] = GetField(attributeType, (string)entry.Key);
                    fieldValues[i] = entry.Value;
                    i += 1;
                }

                WorkaroundCecilBug82814(ref constructorArgs, CollectionUtils.ConvertAllToArray <ParameterInfo, Type>(constructor.GetParameters(),
                                                                                                                     delegate(ParameterInfo parameter) { return(parameter.ParameterType); }));
                WorkaroundCecilBug82814(ref propertyValues, CollectionUtils.ConvertAllToArray <PropertyInfo, Type>(namedProperties,
                                                                                                                   delegate(PropertyInfo property) { return(property.PropertyType); }));
                WorkaroundCecilBug82814(ref fieldValues, CollectionUtils.ConvertAllToArray <FieldInfo, Type>(namedFields,
                                                                                                             delegate(FieldInfo field) { return(field.FieldType); }));

                CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(
                    constructor, constructorArgs,
                    namedProperties, propertyValues,
                    namedFields, fieldValues);
                setCustomAttribute(attributeBuilder);
            }
        }
        private void InitializeCustomAttributes(SetCustomAttributeDelegate setCustomAttribute, CustomAttributeCollection attributes)
        {
            foreach (CustomAttribute attribute in attributes)
            {
                attribute.Resolve();

                ConstructorInfo constructor = ResolveConstructor(attribute.Constructor);
                object[] constructorArgs = CollectionUtils.ToArray<object>(attribute.ConstructorParameters);
                Type attributeType = constructor.ReflectedType;

                PropertyInfo[] namedProperties = new PropertyInfo[attribute.Properties.Count];
                object[] propertyValues = new object[attribute.Properties.Count];
                int i = 0;
                foreach (DictionaryEntry entry in attribute.Properties)
                {
                    namedProperties[i] = GetProperty(attributeType, (string)entry.Key);
                    propertyValues[i] = entry.Value;
                    i += 1;
                }

                FieldInfo[] namedFields = new FieldInfo[attribute.Fields.Count];
                object[] fieldValues = new object[attribute.Fields.Count];
                i = 0;
                foreach (DictionaryEntry entry in attribute.Fields)
                {
                    namedFields[i] = GetField(attributeType, (string)entry.Key);
                    fieldValues[i] = entry.Value;
                    i += 1;
                }

                WorkaroundCecilBug82814(ref constructorArgs, CollectionUtils.ConvertAllToArray<ParameterInfo, Type>(constructor.GetParameters(),
                    delegate(ParameterInfo parameter) { return parameter.ParameterType; }));
                WorkaroundCecilBug82814(ref propertyValues, CollectionUtils.ConvertAllToArray<PropertyInfo, Type>(namedProperties,
                    delegate(PropertyInfo property) { return property.PropertyType; }));
                WorkaroundCecilBug82814(ref fieldValues, CollectionUtils.ConvertAllToArray<FieldInfo, Type>(namedFields,
                    delegate(FieldInfo field) { return field.FieldType; }));

                CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(
                    constructor, constructorArgs,
                    namedProperties, propertyValues,
                    namedFields, fieldValues);
                setCustomAttribute(attributeBuilder);
            }
        }