jeudi 13 août 2015

How can I get the values of all the boolean properties in a C# class using reflection?

Assuming I have a class defined like this:

public class TType
{
    [Key, ForeignKey("Ad")]
    public int AdId { get; set; }

    public bool Classic { get; set; }
    public bool Modern { get; set; }
    public bool Vintage { get; set; }
    public bool Futuristic { get; set; }

    public virtual Ad Ad { get; set; }
}

How can I get the values of only the boolean properties through reflection? If I do something like this, it will iterate through all the properties:

foreach (var item in Model.TType.GetType().GetProperties())
{

}





Aucun commentaire:

Enregistrer un commentaire