このフィールド オブジェクトの型を取得します。
Public MustOverride ReadOnly Property FieldType As Type
[C#]
public abstract Type FieldType {get;}
[C++]
public: __property virtual Type* get_FieldType() = 0;
[JScript]
public abstract function get FieldType() : Type;
プロパティ値
このフィールド オブジェクトの型。
解説
Type は、String、 Boolean 、GUID などのプリミティブ データ型です。
FieldType プロパティを取得するには、最初に Type クラスを取得します。そして、その Type から FieldInfo を取得します。最後に、 FieldInfo から FieldType を取得します。
使用例
フィールドを作成し、その型と FieldInfo を取得して FieldType を表示する例を次に示します。
Imports System
Imports System.Reflection
' Make a field.
Public Class Myfield
Private SomeField As String = "private field"
Public ReadOnly Property Field() As String
Get
Return SomeField
End Get
End Property
End Class 'Myfield
Public Class Myfieldinfo
Public Shared Function Main() As Integer
Console.WriteLine("Reflection.FieldInfo")
Console.WriteLine()
Dim Myfield As New Myfield()
' Get the type and FieldInfo.
Dim MyType As Type = Type.GetType("Myfield")
Dim Myfieldinfo As FieldInfo = MyType.GetField("SomeField", BindingFlags.Instance Or BindingFlags.NonPublic)
' Get and display the FieldType.
Console.WriteLine("{0}.{1} - {2};", MyType.FullName, Myfieldinfo.Name, Myfield.Field)
'Console.WriteLine("{0} - ", Myfieldinfo.Name)
'Console.WriteLine("{0};", Myfield.Field)
Console.WriteLine("FieldType = {0}", Myfieldinfo.FieldType)
Return 0
End Function 'Main
End Class 'Myfieldinfo
[C#]
using System;
using System.Reflection;
// Make a field.
public class Myfield
{
private string field = "private field";
public string Field
{
get{return field;}
}
}
public class Myfieldinfo
{
public static int Main()
{
Console.WriteLine ("\nReflection.FieldInfo");
Myfield Myfield = new Myfield();
// Get the type and FieldInfo.
Type MyType = Type.GetType("Myfield");
FieldInfo Myfieldinfo = MyType.GetField("field", BindingFlags.Instance|BindingFlags.NonPublic);
// Get and display the FieldType.
Console.Write ("\n{0}.", MyType.FullName);
Console.Write ("{0} - ", Myfieldinfo.Name);
Console.Write ("{0};", Myfield.Field);
Console.Write ("\nFieldType = {0}", Myfieldinfo.FieldType);
return 0;
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
// Make a field.
public __gc class Myfield
{
private:
String* field;
public:
Myfield() : field(S"private field") {}
__property String* get_Field() {return field;}
};
int main()
{
Console::WriteLine (S"\nReflection.FieldInfo");
Myfield* myfield = new Myfield();
// Get the type and FieldInfo.
Type* MyType = Type::GetType(S"Myfield");
FieldInfo* Myfieldinfo = MyType->GetField(S"field",
static_cast<BindingFlags>(BindingFlags::Instance|BindingFlags::NonPublic));
// Get and display the FieldType.
Console::Write (S"\n{0}.", MyType->FullName);
Console::Write (S"{0} - ", Myfieldinfo->Name);
Console::Write (S"{0};", myfield->Field);
Console::Write (S"\nFieldType = {0}", Myfieldinfo->FieldType);
return 0;
}
[JScript]
//Make a field
public class Myfield
{
private var field : String = "private field";
public function get Field() : String {
return field;
}
}
public class Myfieldinfo
{
public static function Main() : void
{
Console.WriteLine ("\nReflection.FieldInfo");
var myField : Myfield = new Myfield();
//Get the Type and FieldInfo
var myType : Type = Type.GetType("Myfield");
var myFieldinfo : FieldInfo = myType.GetField("field", BindingFlags.Instance|BindingFlags.NonPublic);
//Get and Display the FieldType
Console.Write ("\n{0}.", myType.FullName);
Console.Write ("{0} - ", myFieldinfo.Name);
Console.Write ("{0};", myField.Field);
Console.Write ("\nFieldType = {0}", myFieldinfo.FieldType);
}
}
Myfieldinfo.Main();
必要条件
プラットフォーム: 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, Common Language Infrastructure (CLI) Standard
参照
FieldInfo クラス | FieldInfo メンバ | System.Reflection 名前空間 | FieldAttributes | Type