Thank's for that, So it appears that IsAssignable function only works with
specified generics types not generic definition types.
The following function now does what I need.
Called like so
IsAssignableFro mGenericType(<S omeTypeToCheck> ,
GetType(Busines sListBase(Of )))
Private Function IsAssignableFro mGenericType(By Val typeToCheck As
System.Type, ByVal genericTypeToCo mpare As System.Type) As Boolean
Do
If typeToCheck.IsG enericType Then
Dim genTypeDef As System.Type = typeToCheck.Get GenericTypeDefi nition
If genTypeDef.Equa ls(genericTypeT oCompare) Then
Return True
End If
End If
typeToCheck = typeToCheck.Bas eType
Loop While typeToCheck.Bas eType IsNot Nothing
End Function
Regards
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:u$******** ******@TK2MSFTN GP14.phx.gbl...
"Joe Adams" <a@b.com> schrieb: How can I use GetType(<Generi cType>).IsAssig nableFrom(<MyTy pe>)
I need to now if the <MyType> is the same type of class as the
<GenericType> without having to add the generic type member members.
i.e. I do not want to use GetType(<Generi cType>(Of
String).IsAssig nableFrom(<MyTy pe>)
I've tried using
GetType(<Generi cType>(Of ,).IsAssignable From(<MyType>) but it always
returns false.
Assuming you have two types 'A' and 'B', and 'B' inherits from 'A'. In
addition, you have a generic class 'Foo(Of T)'. In this case, 'Foo(Of A)'
is not the supertype of 'Foo(Of B)', althoigh 'A' is the supertype of 'B'!
Thus
'GetType(Object ).IsAssignableF rom(Foo(Of ))'
will evaluate to 'True' while
'GetType(Foo(Of A)).IsAssignabl eFrom(GetType(F oo(Of B))'
evaluates to 'False'.
Assuming you have these classes
\\\
Public Class Foo(Of T)
End Class
Public Class Goo
Inherits Goo(Of Integer)
End Class
Public Class Boo
Inherits Goo
End Class
///
then
'GetType(Foo(Of ).IsAssignableF rom(GetType(Goo ))'
will return 'False', although
'GetType(Goo).I sAssignableFrom (GetType(Boo))'
returns 'True'.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>