jeudi 5 mai 2016

C# iterate through class properties and add to list certain types

I want to iterate through all the properties of a class and find all properties of a certain type and add them to a list. The code I use to iterate is:

List<CustomAttribute> attributes = new List<CustomAttribute>();
PropertyInfo[] properties = typeof(CustomClass).GetProperties();

foreach (PropertyInfo property in properties)
{
    if (property.PropertyType == typeof(CustomAttribute))
    {
        //here I want to add property to list
    }
}

Any ideas?

Thanks





Aucun commentaire:

Enregistrer un commentaire