Reflecting a Single Type

Reflecting all types within an assembly can be useful, but in most cases you will probably be interested in reflecting a single type. To accomplish this, you need the instance of a System.Type. Then you need to invoke members described in the previous section. For example, imagine you want to inspect members from the Person class. You first get the type instance, and then you can perform reflection as demonstrated by the following code:

Dim myType As Type = (New People.Person).GetTypeConsole.WriteLine(" Methods:")For Each method In myType.GetMethods    Console.WriteLine("     " + method.ToString)NextConsole.WriteLine(" Properties:")For Each [property] In myType.GetProperties    Console.WriteLine("     " ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.