I’m trying to build a base class that can determine its own type, but I’m not sure how to go, obviously this.GetType doesn’t work inside of a typeOf, so is there any way to get the class type for the current class?
class BassClass {
public string GetValueofSomething() {
Type type = typeof(this.GetType()); //this obviously doesn't work
type = typeOf(BaseClass); //works fine
MemberInfo[] members = type.GetMembers();
//Other stuff here
return ""
}
}
GetType()returns aType, so no need fortypeof:But you should really avoid accessing a derived classes’s members with reflection, is possible. Declare an abstract or virtual member that derived classes can override: