FieldInfo クラスとは? わかりやすく解説

FieldInfo クラス

フィールド属性取得しフィールドメタデータアクセスできるようにします。

名前空間: System.Reflection
アセンブリ: 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
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.None) */ 
public abstract class FieldInfo extends MemberInfo
 implements _FieldInfo
SerializableAttribute 
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.None) 
public abstract class FieldInfo extends
 MemberInfo implements _FieldInfo
解説解説
使用例使用例

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.Object
   System.Reflection.MemberInfo
    System.Reflection.FieldInfo
       Microsoft.JScript.COMFieldInfo
       Microsoft.JScript.JSField
       Microsoft.JScript.JSFieldInfo
       System.Reflection.Emit.FieldBuilder
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「FieldInfo クラス」の関連用語

FieldInfo クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



FieldInfo クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS