dimanche 24 octobre 2021

How to get all properties of a class where the property is based on a certain type

In c# I have a class with properties on it.

public class MyClass
{
   public MyPropClass1 Prop1 { get; set; }
   public MyPropClass2 Prop2 { get; set; }
   public AnotherClassAltogether Prop3 {get; set; }
}

Lets say MyPropClass1 and MyPropClass2 both inherit from MyPropBaseClass but AnotherClassAltogether doesn't.

What is the simplest way to get all properties from MyClass which either are, or somewhere down the chain are inherited from, a class?

E.g. if I wanted to query MyClass for properties based on MyPropBaseClass then it should return Prop1 and Prop2





Aucun commentaire:

Enregistrer un commentaire