_FieldInfo.Attributesとは? わかりやすく解説

FieldInfo.Attributes プロパティ

このフィールド関連付けられている属性取得します

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public MustOverride ReadOnly
 Property Attributes As FieldAttributes
Dim instance As FieldInfo
Dim value As FieldAttributes

value = instance.Attributes
public abstract FieldAttributes Attributes { get;
 }
public:
virtual property FieldAttributes Attributes {
    FieldAttributes get () abstract;
}
/** @property */
public abstract FieldAttributes get_Attributes ()

プロパティ
このフィールドFieldAttributes

解説解説

すべてのメンバには、メンバ特定のに応じて定義されている一連の属性ありますFieldAttributes は、このフィールドプライベート フィールドまたは静的フィールドのいずれであるかなどを通知します

Attributes プロパティ取得するには、最初に Type クラス取得します。そして、その Type から FieldInfo取得します。そして、その FieldInfo から Attributes取得します

使用例使用例

3 つのフィールド作成し、そのフィールド属性表示するコード例次に示しますFieldAttributes 値には、3 番目のフィールドで示すように、PublicLiteral両方など、複数属性含めることができます

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Public Class Demo
    ' Declare three fields.
    ' The first field is private.
    Private m_field As String
 = "String A"

    'The second field is public.
    Public Field As String
 = "String B"

    ' The third field is public and const, hence also static
    ' and literal with a default value.
    Public Const FieldC As
 String = "String C"

End Class

Module Module1
    Sub Main()
        ' Create an instance of the Demo class.
        Dim d As New Demo()

        Console.WriteLine(vbCrLf & "Reflection.FieldAttributes")

        ' Get a Type object for Demo, and a FieldInfo for each of
        ' the three fields. Use the FieldInfo to display field
        ' name, value for the Demo object in d, and attributes.
        '
        Dim myType As Type = GetType(Demo)

        Dim fiPrivate As FieldInfo = myType.GetField("m_field",
 _
            BindingFlags.NonPublic Or BindingFlags.Instance)
        DisplayField(d, fiPrivate)

        Dim fiPublic As FieldInfo = myType.GetField("Field",
 _
            BindingFlags.Public Or BindingFlags.Instance)
        DisplayField(d, fiPublic)

        Dim fiConstant As FieldInfo = myType.GetField("FieldC",
 _
            BindingFlags.Public Or BindingFlags.Static)
        DisplayField(d, fiConstant)
    End Sub

    Sub DisplayField(ByVal obj As
 Object, ByVal f As FieldInfo)

        ' Display the field name, value, and attributes.
        '
        Console.WriteLine("{0} = ""{1}"";
 attributes: {2}", _
            f.Name, f.GetValue(obj), f.Attributes)
    End Sub

End Module

' This code example produces the following output:
'
'm_field = "String A"; attributes: Private
'Field = "String B"; attributes: Public
'FieldC = "String C"; attributes: Public, Static, Literal,
 HasDefault
using System;
using System.Reflection;

public class Demo
{
    // Make three fields:
    // The first field is private.
    private string m_field = "String A";

    // The second field is public.
    public string Field = "String B";

    // The third field is public const (hence also literal and static)
,
    // with a default value.
    public const string
 FieldC = "String C";
}

public class Myfieldattributes
{
    public static void Main()
    {
        Console.WriteLine ("\nReflection.FieldAttributes");
        Demo d = new Demo();
 
        // Get a Type object for Demo, and a FieldInfo for each of
        // the three fields. Use the FieldInfo to display field
        // name, value for the Demo object in d, and attributes.
        //
        Type myType = typeof(Demo);
        FieldInfo fiPrivate = myType.GetField("m_field",
            BindingFlags.NonPublic | BindingFlags.Instance);
        DisplayField(d, fiPrivate);

        FieldInfo fiPublic = myType.GetField("Field",
            BindingFlags.Public | BindingFlags.Instance);
        DisplayField(d, fiPublic);

        FieldInfo fiConstant = myType.GetField("FieldC",
            BindingFlags.Public | BindingFlags.Static);
        DisplayField(d, fiConstant);
    }

    static void DisplayField(Object obj, FieldInfo
 f)
    { 
        // Display the field name, value, and attributes.
        //
        Console.WriteLine("{0} = \"{1}\"; attributes: {2}", 
            f.Name, f.GetValue(obj), f.Attributes);
    }
}

/* This code example produces the following output:

Reflection.FieldAttributes
m_field = "String A"; attributes: Private
Field = "String B"; attributes: Public
FieldC = "String C"; attributes: Public, Static, Literal, HasDefault
 */
using namespace System;
using namespace System::Reflection;
using namespace System::Security::Permissions;

public ref class Demo
{
private:
    // Make three fields:
    // The first field is private.
    String^ m_field;

    // The second field is public.
public:
    String^ Field;

    // The third field is public and literal. 
    literal String^ FieldC = "String C";

    Demo() { m_field = "String A"; Field = "String B"; }
};

static void DisplayField(Object^ obj, FieldInfo^
 f)
{ 
    // Display the field name, value, and attributes.
    //
    Console::WriteLine("{0} = \"{1}\"; attributes: {2}", 
        f->Name, f->GetValue(obj), f->Attributes);
};

void main()
{
    Console::WriteLine ("\nReflection.FieldAttributes");
    Demo^ d = gcnew Demo();

    // Get a Type object for Demo, and a FieldInfo for each of
    // the three fields. Use the FieldInfo to display field
    // name, value for the Demo object in d, and attributes.
    //
    Type^ myType = Demo::typeid;

    FieldInfo^ fiPrivate = myType->GetField("m_field",
        BindingFlags::NonPublic | BindingFlags::Instance);
    DisplayField(d, fiPrivate);

    FieldInfo^ fiPublic = myType->GetField("Field",
        BindingFlags::Public | BindingFlags::Instance);
    DisplayField(d, fiPublic);

    FieldInfo^ fiConstant = myType->GetField("FieldC",
        BindingFlags::Public | BindingFlags::Static);
    DisplayField(d, fiConstant);
}

/* This code example produces the following output:

Reflection.FieldAttributes
m_field = "String A"; attributes: Private
Field = "String B"; attributes: Public
FieldC = "String C"; attributes: Public, Static, Literal, HasDefault
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

_FieldInfo.Attributes プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

COM オブジェクトに、Attributes プロパティへのバージョン依存しないアクセス用意されています。

このプロパティは、CLS準拠していません。  

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim instance As _FieldInfo
Dim value As FieldAttributes

value = instance.Attributes
FieldAttributes Attributes { get; }
property FieldAttributes Attributes {
    FieldAttributes get ();
}
/** @property */
FieldAttributes get_Attributes ()
function get Attributes () : FieldAttributes

プロパティ
このフィールドの FieldAttributes。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
_FieldInfo インターフェイス
_FieldInfo メンバ
System.Runtime.InteropServices 名前空間



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

辞書ショートカット

すべての辞書の索引

_FieldInfo.Attributesのお隣キーワード
検索ランキング

   

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



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

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

©2024 GRAS Group, Inc.RSS