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