Mega Code Archive

 
Categories / VB.Net / Reflection
 

Type GetNestedTypes (BindingFlags)

Imports System Imports System.Reflection Imports System.Reflection.Emit Imports Microsoft.VisualBasic Public Class MyTypeClass     Public Class Myclass1     End Class 'Myclass1     Public Class Myclass2     End Class 'Myclass2     Protected Class MyClass3     End Class 'MyClass3     Protected Class MyClass4     End Class 'MyClass4 End Class 'MyTypeClass Public Class TypeMain     Public Shared Sub Main()         Dim myType As Type = GetType(MyTypeClass)         Dim myTypeArray As Type() = myType.GetNestedTypes((BindingFlags.Public Or BindingFlags.Instance))         Console.WriteLine("The number of public nested classes is {0}.", myTypeArray.Length.ToString())         DisplayTypeInfo(myTypeArray)     End Sub 'Main     Public Shared Sub DisplayTypeInfo(ByVal myArrayType() As Type)         Dim i As Integer         For i = 0 To myArrayType.Length - 1             Dim myType As Type = CType(myArrayType(i), Type)             Console.WriteLine("The name of the nested class is {0}.", myType.ToString())         Next i     End Sub  End Class