フィールドの内部メタデータ形式を識別するハンドルである RuntimeFieldHandle を取得します。
Public MustOverride ReadOnly Property FieldHandle As _
RuntimeFieldHandle
[C#]
public abstract RuntimeFieldHandle FieldHandle {get;}
[C++]
public: __property virtual RuntimeFieldHandle get_FieldHandle() = 0;
[JScript]
public abstract function get FieldHandle() : RuntimeFieldHandle;
プロパティ値
フィールドの内部メタデータ形式を識別するハンドル。
解説
ハンドルは取得されたアプリケーション ドメインでだけ有効です。
使用例
[Visual Basic, C#, C++] MyClass.MyField のフィールド情報を取得し、フィールド ハンドルと関連付けられているフィールドを表示する例を次に示します。
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class [MyClass]
Public MyField As String = "Microsoft"
End Class '[MyClass]
Public Class FieldInfo_FieldHandle
Public Shared Sub Main()
Dim [myClass] As New [MyClass]()
' Get the type of MyClass.
Dim myType As Type = GetType([MyClass])
Try
' Get the field information of MyField.
Dim myFieldInfo As FieldInfo = myType.GetField("MyField", BindingFlags.Public Or BindingFlags.Instance)
' Determine whether or not the FieldInfo object is null.
If Not (myFieldInfo Is Nothing) Then
' Get the handle for the field.
Dim myFieldHandle As RuntimeFieldHandle = myFieldInfo.FieldHandle
DisplayFieldHandle(myFieldHandle)
Else
Console.WriteLine("The myFieldInfo object is null.")
End If
Catch e As Exception
Console.WriteLine(" Exception: {0}", e.Message.ToString())
End Try
End Sub 'Main
Public Shared Sub DisplayFieldHandle(ByVal myFieldHandle As RuntimeFieldHandle)
' Get the type from the handle.
Dim myField As FieldInfo = FieldInfo.GetFieldFromHandle(myFieldHandle)
' Display the type.
Console.WriteLine(ControlChars.Cr + "Displaying the field from the handle." + ControlChars.Cr)
Console.WriteLine("The type is {0}.", myField.ToString())
End Sub 'DisplayFieldHandle
End Class 'FieldInfo_FieldHandle
[C#]
using System;
using System.Reflection;
public class MyClass
{
public string MyField = "Microsoft";
}
public class FieldInfo_FieldHandle
{
public static void Main()
{
MyClass myClass =new MyClass();
// Get the type of MyClass.
Type myType = typeof(MyClass);
try
{
// Get the field information of MyField.
FieldInfo myFieldInfo = myType.GetField("MyField", BindingFlags.Public
| BindingFlags.Instance);
// Determine whether or not the FieldInfo object is null.
if(myFieldInfo!=null)
{
// Get the handle for the field.
RuntimeFieldHandle myFieldHandle=myFieldInfo.FieldHandle;
DisplayFieldHandle(myFieldHandle);
}
else
{
Console.WriteLine("The myFieldInfo object is null.");
}
}
catch(Exception e)
{
Console.WriteLine("Exception: {0}", e.Message);
}
}
public static void DisplayFieldHandle(RuntimeFieldHandle myFieldHandle)
{
// Get the type from the handle.
FieldInfo myField = FieldInfo.GetFieldFromHandle(myFieldHandle);
// Display the type.
Console.WriteLine("\nDisplaying the field from the handle.\n");
Console.WriteLine("The type is {0}.", myField.ToString());
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
public __gc class MyClass
{
public:
String* MyField;
};
void DisplayFieldHandle(RuntimeFieldHandle myFieldHandle)
{
// Get the type from the handle.
FieldInfo* myField = FieldInfo::GetFieldFromHandle(myFieldHandle);
// Display the type.
Console::WriteLine(S"\nDisplaying the field from the handle.\n");
Console::WriteLine(S"The type is {0}.", myField);
}
int main()
{
MyClass* myClass = new MyClass();
// Get the type of MyClass.
Type* myType = __typeof(MyClass);
try {
// Get the field information of MyField.
FieldInfo* myFieldInfo = myType->GetField(S"MyField",
static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance));
// Determine whether or not the FieldInfo Object* is 0.
if (myFieldInfo!=0) {
// Get the handle for the field.
RuntimeFieldHandle myFieldHandle=myFieldInfo->FieldHandle;
DisplayFieldHandle(myFieldHandle);
} else {
Console::WriteLine(S"The myFieldInfo Object* is 0.");
}
} catch (Exception* e) {
Console::WriteLine(S"Exception: {0}", e->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET