A read about creating types at runtime and i found it amazing. My goal is to create this class:
[DelimitedRecord(\",\")]
public class Person
{
[FieldOrder(0
I made it work:
//create the Delimiter attribute
Type[] attributeParams = new Type[] { typeof(string) };
ConstructorInfo classCtorInfo = typeof(DelimitedRecordAttribute).GetConstructor(attributeParams);
CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(classCtorInfo, new object[] { ";" });
typeBuilder.SetCustomAttribute(attributeBuilder);
This would do the job for the field attributes:
//create the firstName attribute [FieldOrder(0)]
Type[] firstNameFieldOrderAttributeParams = new Type[] { typeof(int) };
ConstructorInfo firstNameFieldOrderAttrInfo = typeof(FieldOrderAttribute).GetConstructor(firstNameFieldOrderAttributeParams);
CustomAttributeBuilder firstNameFieldOrderAttributeBuilder = new CustomAttributeBuilder(firstNameFieldOrderAttrInfo, new object[] { 0 });
firstNameField.SetCustomAttribute(firstNameFieldOrderAttributeBuilder);