A custom attribute class is built in the same way any other class is built, using DefineType off ModuleBuilder.
Reflection Emit supports defining custom attributes directly on a member thought the ICustomAttributeBuilder interface. This interface is defined on MethodBuilder, TypeBuilder, ConstructorBuilder, ParamaterInfo, ModuleBuilder and Assembly.
interface ICustomAttributeBuilder { public void DefineCustomAttribute(ConstructorInfo attributeType, byte [] attributeData); } public class CustomAttributeHelper { public static byte [] GetAttributeData (ConstructorInfo attributeType); public static byte [] GetAttributeData (ConstructorInfo attributeType, Variant [] paramaterValues); public static byte [] GetAttributeData (ConstructorInfo attributeType, Variant [] parameterValues, String [] members, Variant [] memeberValue); public static byte [] GetAttributeData (Object attributeInstance); }
Defines a custom attribute on this member represented by attributeType with the data from attributeData. See the metadata spec "http://comrtime/specs/Formats/MiniSpec%20Metadata%20Extensibility.doc" for details on how to lay out the attributeData or use the methods on CustomAttributeHelper to build the byte array.
Returns the byte [] needed for DefineCustomAttribute() given the constructor from the attribute type, the values for that constructor and the names and values for the properties or fields of the custom attribute.