vendredi 24 mars 2017

C# return a list of all required properties in a class

I'm trying to get a dictionary containing the Property and the DisplayName of all properties in a class that have the Required Attribute.

I'm trying to work off of this extension method that I have but PropertyDescriptor does not contain a definition for Required. Any direction would be appreciated

    public static Dictionary<string, string> GetDisplayNameList<T>()
    {
        var info = TypeDescriptor.GetProperties(typeof(T))
            .Cast<PropertyDescriptor>()
            .ToDictionary(p => p.Name, p => p.DisplayName);
        return info;
    }





Aucun commentaire:

Enregistrer un commentaire