How to dynamically obtain all non-generic classes that inherit from the Person class (Student, Teacher) and properties (Address) for the Person class.
Example code:
[DataContract]
[KnownType(typeof(Student))]
[KnownType(typeof(Teacher))]
public abstract class Person {
[DataMember]
public string Name { get; set; }
[DataMember]
public string Surname { get; set; }
[DataMember]
public Address _Address { get; set; }
}
To look for all classes that inherit Person, you need to define where you are looking. You can’t look everywhere. Suppose that all classes are in the same assembly as the Person class you can write that:
As for the properties, do the same in a foreach loop on all properties: