Mega Code Archive

 
Categories / VB.Net / Reflection
 

Type IsArrayImpl tells whether the Type is an array

Imports System Imports System.Reflection Imports Microsoft.VisualBasic Public Class MyTypeDelegator     Inherits TypeDelegator     Public myElementType As String = Nothing     Public myType As Type     Public Sub New(ByVal myType As Type)         MyBase.New(myType)         Me.myType = myType     End Sub      Protected Overrides Function IsArrayImpl() As Boolean         If myType.IsArray Then             myElementType = "array"             Return True         End If         Return False     End Function  End Class  Public Class Type_IsArrayImpl     Public Shared Sub Main()         Try             Dim myInt As Integer = 0             Dim myArray(4) As Integer             Dim myType As New MyTypeDelegator(myArray.GetType())             If myType.IsArray Then                 Console.WriteLine("The type of myArray is {0}.", myType.myElementType)             Else                 Console.WriteLine("myArray is not an array.")             End If         Catch e As Exception             Console.WriteLine("Exception: {0}", e.Message.ToString())         End Try     End Sub  End Class