How can i read all class Properties, without having an instantiated object of this Class nor hard-coding the name of the class itself? The name of the class is stored in a string-variable.
string className = "myNamespace.myClass";
PropertyInfo[] myPropertyInfo;
try
{
myPropertyInfo = Type.GetType(className).GetProperties();
} catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
always returns a
System.NullReferenceException: Object reference not set to an instance of an object.
I'd like avoiding a solution like
switch(className) {
case "myNamespace.myClass":
myNamespace.myClass obj = new();
break;
case "myNamespace.anotherClass":
myNamespace.anotherClass obj = new();
break;
case "anotherNamespace.myClass":
anotherNamespace.myClass obj = new();
break;
}
myPropertyInfo = obj.GetType().GetProperties();