I have started using reflection and am a bit confused about getting PropertyInfo.
I do something like this and it works:
Dim x as New MyClass
Dim prop as PropertyInfo = x.GetType.GetProperty("Name")
I don’t understand why I must have an instance of the class in order to get a property from it. If GetType returns a Type object, why couldn’t I just reference the type itself?
Dim prop as PropertyInfo = GetType(MyClass).GetProperty("Name")
or
Dim prop as PropertyInfo = MyClass.GetType.GetProperty("Name")
That is exactly correct.