lundi 18 mars 2019

adding custom attributes and getting properties from dynamic object

I have this scenario where we use model classes to generate an excel file, however due to the new requests it requires to process Dynamic objects that includes the attributes which are necessary to be processed by the excel file code generator.

So if I have model, let's say User:

[Sheet]
public class User 
{
    [Column]
    public string FirstName { get; set; }

    [Column]
    public string LastName { get; set; }

    [Column]
    public string EmailAddress { get; set; }
}

So if a user does not want to include the EmailAddress field this should be excluded when export engine try to do model.GetType().GetProperties() to process the property name and its value to the excel.

I tried to use the ExpandoObject however it does not work when I try to access the properties through model.GetType().GetProperties() even if I have passed the whole PropertyInfo to the IDictionary<string, object> value.

How do I do this using dynamic? FYI the custom attribute is import to be included as part of the object and it's property because there is a filtering using these attribute to process even further the model class.





Aucun commentaire:

Enregistrer un commentaire