I’m using reflection to get the properties of an object and there’s no difficulty in that but I need to make my class even more generic so basically what I’m trying to do is the following:
PropertyInfo[] properties = (typeof ('ObjectName')).GetProperties(BindingFlags.Public | BindingFlags.Instance);
Or something similar. Notice the use of a string inside the typeof. I know this doesn’t work, this is just to show what I’m trying to accomplish. I’ve also tried:
public void Test(object myObject) { typeof(myObject.GetType()); Type myType = myObject.GetType(); typeof(myType); }
with no success.
If you just want to get the
Typeof the object in question, use theobject.GetType()method, like this:This assumes that you have an instance of the type already, but that you don’t know what the type would be at compile time, or that it could be any type.