All entries for Monday 03 October 2005

October 03, 2005

Breaking Generics in .NET

Consider this simple VB.NET console application:
Module Module1

Sub Main()
Dim baseType As Type = GetType(BaseTest(Of IParameter))
Dim childType As Type = GetType(SubTest)
Dim foo As Boolean = baseType.IsAssignableFrom(childType)
If foo Then
Console.WriteLine("Everything is fine")
Else
Console.WriteLine("WTF?! baseType is NOT assignable from childType!")
End If

Console.ReadLine()
End Sub

End Module


Interface ITest

End Interface


Class BaseTest(Of T As IParameter)
Implements ITest

End Class


Class SubTest
Inherits BaseTest(Of Parameter)

End Class


Interface IParameter

End Interface


Class Parameter
Implements IParameter
End Class

Some how SubTest cannot be casted to BaseTest(Of IParameter)

Any ideas?


Google Ads

Search this blog

Most recent comments

  • I scratched my eye while i was holding some kind of plastic packaging.. Anyways the corner of the pl… by Ercan on this entry
  • About a year ago my contacts that i was wearing, i guess were fautly, because shortly after they wer… by Jon on this entry
  • I got shower gel in my eye 4 and a half days ago, and becasue i rubbed my eyes a lot, i have scratch… by Chris on this entry
  • This website may help http://www.webmd.com/eye–health/tc/Eye–Injuries–Home–Treatment by S on this entry
  • I somehow got dirt, or debris in my eye. The terrible pain sent me in a tailspin. I was afraid of sa… by Bobbi on this entry

Tags

October 2005

Mo Tu We Th Fr Sa Su
Sep |  Today  | Nov
               1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31                  

Galleries

Blog archive

Loading…
Not signed in
Sign in

Powered by BlogBuilder
© MMXXI