Nullable.GetUnderlyingType メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Public Shared Function GetUnderlyingType ( _ nullableType As Type _ ) As Type
Dim nullableType As Type Dim returnValue As Type returnValue = Nullable.GetUnderlyingType(nullableType)
戻り値
nullableType パラメータがクローズ ジェネリック NULL 許容型の場合は nullableType パラメータの型引数。それ以外の場合は null 参照 (Visual Basic では Nothing)。

例外の種類 | 条件 |
---|---|
ArgumentNullException | nullableType が null 参照 (Visual Basic では Nothing) です。 |

ジェネリック型定義は、型パラメータ リストを含む Nullable のような型宣言であり、型パラメータ リストは 1 つ以上の型パラメータを宣言します。クローズ ジェネリック型は、型パラメータに特定の型が指定された型宣言です。
たとえば、nullableType パラメータが C# で Nullable<Int32> 型 (Visual Basic の場合は Nullable(Of Int32) 型) である場合、戻り値は、Int32 型 (クローズ ジェネリック型の型引数) です。

戻り値が Int32 の Nullable 型であるメソッドを定義するコード例を次に示します。このコード例では、GetUnderlyingType メソッドを使用して、戻り値の型引数を表示します。
' This code example demonstrates the ' Nullable.GetUnderlyingType() method. Imports System Imports System.Reflection Class Sample ' Declare a type named Example. ' The MyMethod member of Example returns a Nullable of Int32. Public Class Example Public Function MyMethod() As Nullable(Of Integer) Return 0 End Function End Class 'Example ' ' Use reflection to obtain a Type object for the Example type. ' Use the Type object to obtain a MethodInfo object for the MyMethod method. ' Use the MethodInfo object to obtain the type of the return value of ' MyMethod, which is Nullable of Int32. ' Use the GetUnderlyingType method to obtain the type argument of the ' return value type, which is Int32. ' Public Shared Sub Main() Dim t As Type = GetType(Example) Dim mi As MethodInfo = t.GetMethod("MyMethod") Dim retval As Type = mi.ReturnType Console.WriteLine("Return value type ... {0}", retval) Dim answer As Type = Nullable.GetUnderlyingType(retval) Console.WriteLine("Underlying type ..... {0}", answer) End Sub 'Main End Class 'Sample ' 'This code example produces the following results: ' 'Return value type ... System.Nullable`1[System.Int32] 'Underlying type ..... System.Int32 '
// This code example demonstrates the // Nullable.GetUnderlyingType() method. using System; using System.Reflection; class Sample { // Declare a type named Example. // The MyMethod member of Example returns a Nullable of Int32. public class Example { public int? MyMethod() { return 0; } } /* Use reflection to obtain a Type object for the Example type. Use the Type object to obtain a MethodInfo object for the MyMethod method. Use the MethodInfo object to obtain the type of the return value of MyMethod, which is Nullable of Int32. Use the GetUnderlyingType method to obtain the type argument of the return value type, which is Int32. */ public static void Main() { Type t = typeof(Example); MethodInfo mi = t.GetMethod("MyMethod"); Type retval = mi.ReturnType; Console.WriteLine("Return value type ... {0}", retval); Type answer = Nullable.GetUnderlyingType(retval); Console.WriteLine("Underlying type ..... {0}", answer); } } /* This code example produces the following results: Return value type ... System.Nullable`1[System.Int32] Underlying type ..... System.Int32 */

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Nullable.GetUnderlyingType メソッドのページへのリンク