In VB.NET puoi utilizzare il metodo
Nullable.GetUnderlyingType(...). Ti invio un esempio:
Public Function CheckType(Of T)(ByVal arg As T) As System.Type
Return GetType(T)
End Function
Public Function IsNullable(Of T)(ByVal arg As T) As Boolean
Return Nullable.GetUnderlyingType(GetType(T)) IsNot Nothing
End Function
Sub Main()
Dim test0 As Integer = 0
Dim test1? As Integer = 1
Dim test2 As Integer? = 2
Dim test3 As Nullable(Of Integer) = 3
Dim test4 As Boolean = False
Dim test5 As Nullable(Of Boolean) = Nothing
Dim test6 As DateTime = DateTime.Now()
Dim test7 As Nullable(Of DateTime) = Nothing
Console.WriteLine(CheckType(test0).ToString() & " - IsNullable: " & IsNullable(test0))
Console.WriteLine(CheckType(test1).ToString() & " - IsNullable: " & IsNullable(test1))
Console.WriteLine(CheckType(test2).ToString() & " - IsNullable: " & IsNullable(test2))
Console.WriteLine(CheckType(test3).ToString() & " - IsNullable: " & IsNullable(test3))
Console.WriteLine(CheckType(test4).ToString() & " - IsNullable: " & IsNullable(test4))
Console.WriteLine(CheckType(test5).ToString() & " - IsNullable: " & IsNullable(test5))
Console.WriteLine(CheckType(test6).ToString() & " - IsNullable: " & IsNullable(test6))
Console.WriteLine(CheckType(test7).ToString() & " - IsNullable: " & IsNullable(test7))
Console.WriteLine("Premi un tasto per chiudere...")
Console.ReadKey()
End Sub
Ciao!
Modificato da giaesp il 02 gennaio 2012 12.42 -