mercredi 4 septembre 2019

How to modify "Order" of "DataMember" attribute at runtime?

I have a datamembers where order values are mentioned. i want to modify the value according to the order of parameters present in select query. I am unable to set the order value for the datamember at runtime.

Below is the code i tried :

[DataContract]
    public class Details
    {
        [DataMember(EmitDefaultValue = false, Order = 1)]
        public string id;
        [DataMember(EmitDefaultValue = false, Order = 1)]
        public string name;
        [DataMember(EmitDefaultValue = false, Order = 1)]
        public string creator;
        [DataMember(EmitDefaultValue = false, Order = 1)]
        public string format;
        [DataMember(EmitDefaultValue = false, Order = 1)]
        public string creationTime;
    }

Type type = executing.GetType("Details");
FieldInfo[] properties = type.GetFields();
properties[0].GetCustomAttributes(typeof(DataMemberAttribute), true).SetValue(2, 3);

I tried the above code to get custom attribute and set value, but its not working. Is it possible to change attribute values during runtime?





Aucun commentaire:

Enregistrer un commentaire