I want to get all types in certain assembly that have declared a property with a specific name:
public class Car
{
public WheelInfo WHEEL { get; set; }
}
public class Plane
{
public WheelInfo WHEEL { get; set; }
}
Note that these classes are not derived from the same base class that implements WHEEL
but actually those are different properties that just happen to have the same name.
What would be the proper approach to this using reflection in C#? There are 200+ classes in the assembly that will be searched.
Right now I can check if a type ABC has a property XYZ declared this way:
Type t = typeof(MyAssembly).Assembly.GetType("MyAssembly.ABC");
var customProperty = t.GetProperty("XYZ"); //check if it is null
But I don't know if there is a better way of just getting all types and for each search all properties and see if any is named as the input sting.
Aucun commentaire:
Enregistrer un commentaire