Hello. I have a function
Public MyObj as Object
Public Function Test(t as Type) as Boolean
Return TypeOf MyObj is t ' does not work
End Function
Thanks.
* EDIT
====================================================================
For clarity I will use a complete example, a little modified that initially was thought.
I use an interface, and would like to know if the objects(implementing I) passed in argument are the same type as a internal field(I; A:I; AA:A; B:I).
First of all, (a) I need the exact class identification (only A=A, B=B, AA=AA) and I'd like also (b) to have a "inheritance equivalency" (A=A and A=AA but A<>B)
Option Strict On
Option Explicit On
Public Class Form1
' object to test
Private objI As I
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim aObj As New A
Dim aaObj As New AA
Dim bObj As New B
'assing the object to test - A
Me.objI = New A
'test it
MessageBox.Show(SameTypeAs(aObj).ToString()) ' need True here
MessageBox.Show(SameTypeAs(bObj).ToString()) ' need False here
MessageBox.Show(SameTypeAs(aaObj).ToString()) ' need a)Flase and b)True here
End Sub
Function SameTypeAs(ByVal iObj As I) As Boolean
' here is the "problem":
' how to detect the same (sub)types of I?
Return Me.objI Is iObj
End Function
' interface..........
Interface I
End Interface
' class A..........
Class A
Implements I
End Class
' class B..........
Class B
Implements I
End Class
' class AA..........
Class AA
Inherits A
End Class
End Class