Mega Code Archive

 
Categories / VB.Net / Reflection
 

Type IsInstanceOfType determines whether the specified object is an instance of the current Type

Imports System Public Interface IMyIfc End Interface 'IMyIfc Public Class [MyClass]     Implements IMyIfc End Class Public Class MyDerivedClass     Inherits [MyClass] End Class Class IsInstanceTest     Public Shared Sub Main()         Dim imyifcType As Type = GetType(IMyIfc)         Dim mc As New [MyClass]()         Dim mcType As Type = mc.GetType()         Dim mdc = New MyDerivedClass()         Dim mdcType As Type = mdc.GetType()         Dim array(10) As Integer         Dim arrayType As Type = GetType(Array)                  Console.WriteLine("Is int[] an instance of the Array class? {0}.", arrayType.IsInstanceOfType(array))         Console.WriteLine("Is myclass an instance of MyClass? {0}.", mcType.IsInstanceOfType(mc))         Console.WriteLine("Is myderivedclass an instance of MyClass? {0}.", mcType.IsInstanceOfType(mdc))         Console.WriteLine("Is myclass an instance of IMyIfc? {0}.", imyifcType.IsInstanceOfType(mc))         Console.WriteLine("Is myderivedclass an instance of IMyIfc? {0}.", imyifcType.IsInstanceOfType(mdc))     End Sub  End Class