FieldInfo クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<SerializableAttribute> _ <ComVisibleAttribute(True)> _ <ClassInterfaceAttribute(ClassInterfaceType.None)> _ Public MustInherit Class FieldInfo Inherits MemberInfo Implements _FieldInfo
[SerializableAttribute] [ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType.None)] public abstract class FieldInfo : MemberInfo, _FieldInfo
[SerializableAttribute] [ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType::None)] public ref class FieldInfo abstract : public MemberInfo, _FieldInfo

フィールド情報はメタデータから取得します。FieldInfo クラスには、パブリック コンストラクタがありません。FieldInfo オブジェクトは、Type オブジェクトの GetFields メソッドまたは GetField メソッドを呼び出すことによって取得します。
フィールドとは、クラスで定義される変数です。FieldInfo によって、クラス内のフィールドのメタデータにアクセスでき、フィールドの機能を動的に設定または取得できます。オブジェクトで invoke メソッドや get メソッドが呼び出されるまで、クラスはメモリに読み込まれません。
継承時の注意 FieldInfo から継承する場合は、GetValue および SetValue の両メンバをオーバーライドする必要があります。
Type.GetFields メソッドを使用して FieldInfo クラスからフィールド関連の情報を取得し、フィールドの属性情報を表示する例を次に示します。
Imports System Imports System.Reflection Imports Microsoft.VisualBasic Public Class FieldInfoClass Public myField1 As Integer = 0 Protected myField2 As String = Nothing Public Shared Sub Main() Dim myFieldInfo() As FieldInfo Dim myType As Type = GetType(FieldInfoClass) ' Get the type and fields of FieldInfoClass. myFieldInfo = myType.GetFields(BindingFlags.NonPublic Or _ BindingFlags.Instance Or BindingFlags.Public) Console.WriteLine(ControlChars.NewLine & "The fields of " & _ "FieldInfoClass class are " & ControlChars.NewLine) ' Display the field information of FieldInfoClass. Dim i As Integer For i = 0 To myFieldInfo.Length - 1 Console.WriteLine(ControlChars.NewLine + "Name : {0}", myFieldInfo(i).Name) Console.WriteLine("Declaring Type : {0}", myFieldInfo(i).DeclaringType) Console.WriteLine("IsPublic : {0}", myFieldInfo(i).IsPublic) Console.WriteLine("MemberType : {0}", myFieldInfo(i).MemberType) Console.WriteLine("FieldType : {0}", myFieldInfo(i).FieldType) Console.WriteLine("IsFamily : {0}", myFieldInfo(i).IsFamily) Next i End Sub End Class
using System; using System.Reflection; public class FieldInfoClass { public int myField1 = 0; protected string myField2 = null; public static void Main() { FieldInfo[] myFieldInfo; Type myType = typeof(FieldInfoClass); // Get the type and fields of FieldInfoClass. myFieldInfo = myType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); Console.WriteLine("\nThe fields of " + "FieldInfoClass are \n"); // Display the field information of FieldInfoClass. for(int i = 0; i < myFieldInfo.Length; i++) { Console.WriteLine("\nName : {0}", myFieldInfo[i].Name); Console.WriteLine("Declaring Type : {0}", myFieldInfo[i].DeclaringType); Console.WriteLine("IsPublic : {0}", myFieldInfo[i].IsPublic); Console.WriteLine("MemberType : {0}", myFieldInfo[i].MemberType); Console.WriteLine("FieldType : {0}", myFieldInfo[i].FieldType); Console.WriteLine("IsFamily : {0}", myFieldInfo[i].IsFamily); } } }
using namespace System; using namespace System::Reflection; public ref class FieldInfoClass { public: int myField1; protected: String^ myField2; }; int main() { array<FieldInfo^>^myFieldInfo; Type^ myType = FieldInfoClass::typeid; // Get the type and fields of FieldInfoClass. myFieldInfo = myType->GetFields( static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::Public) ); Console::WriteLine( "\nThe fields of FieldInfoClass are \n" ); // Display the field information of FieldInfoClass. for ( int i = 0; i < myFieldInfo->Length; i++ ) { Console::WriteLine( "\nName : {0}", myFieldInfo[ i ]->Name ); Console::WriteLine( "Declaring Type : {0}", myFieldInfo[ i ]->DeclaringType ); Console::WriteLine( "IsPublic : {0}", myFieldInfo[ i ]->IsPublic ); Console::WriteLine( "MemberType : {0}", myFieldInfo[ i ]->MemberType ); Console::WriteLine( "FieldType : {0}", myFieldInfo[ i ]->FieldType ); Console::WriteLine( "IsFamily : {0}", myFieldInfo[ i ]->IsFamily ); } }
import System.*; import System.Reflection.*; public class FieldInfoClass { public int myField1 = 0; protected String myField2 = null; public static void main(String[] args) { FieldInfo myFieldInfo[]; Type myType = FieldInfoClass.class.ToType(); // Get the type and fields of FieldInfoClass. myFieldInfo = myType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); Console.WriteLine("\nThe fields of " + "FieldInfoClass are \n"); // Display the field information of FieldInfoClass. for (int i = 0; i < myFieldInfo.length; i++) { Console.WriteLine("\nName : {0}", myFieldInfo[i].get_Name()); Console.WriteLine("Declaring Type : {0}", myFieldInfo[i].get_DeclaringType()); Console.WriteLine("IsPublic : {0}", System.Convert.ToString(myFieldInfo[i].get_IsPublic())); Console.WriteLine("MemberType : {0}", myFieldInfo[i].get_MemberType()); Console.WriteLine("FieldType : {0}", myFieldInfo[i].get_FieldType()); Console.WriteLine("IsFamily : {0}", System.Convert.ToString(myFieldInfo[i].get_IsFamily())); } } //main } //FieldInfoClass

System.Reflection.MemberInfo
System.Reflection.FieldInfo
Microsoft.JScript.COMFieldInfo
Microsoft.JScript.JSField
Microsoft.JScript.JSFieldInfo
System.Reflection.Emit.FieldBuilder


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


- FieldInfo クラスのページへのリンク