lundi 13 août 2018

C Sharp Get Description of Property [duplicate]

this is my test class , to get name of property and value of property. There are same topics about enum .But I can not find about class

public class A
{
    [Description("description x")]
    public string X { get; set; }


    [Description("description y")]
    public int Y { get; set; }


    [Description("description z")]
    public int? Z { get; set; }

}

I gets name and value as below

 StringBuilder sb = new StringBuilder();

        PropertyInfo[] properties = a.GetType().GetProperties();
        foreach (PropertyInfo pi in properties)
        {
            sb.Append(
                string.Format(" Name: {0} | Value: {1} ",
                    pi.Name,
                    pi.GetValue(a, null)
                )
            );
        }

Now , I want to get description , How can I ?





Aucun commentaire:

Enregistrer un commentaire