_FieldInfo.IsPrivate プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > _FieldInfo.IsPrivate プロパティの意味・解説 

_FieldInfo.IsPrivate プロパティ

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

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

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

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

Dim instance As _FieldInfo
Dim value As Boolean

value = instance.IsPrivate
bool IsPrivate { get; }
property bool IsPrivate {
    bool get ();
}
/** @property */
boolean get_IsPrivate ()

プロパティ
フィールドプライベート場合trueそれ以外場合false

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

FieldInfo.IsPrivate プロパティ

フィールドプライベートかどうかを示す値を取得します

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

解説解説

プライベート フィールドアクセスできるのは、メンバ関数だけです。

IsPrivate プロパティは、FieldAttributes.Private 属性設定されたときに設定されます。

IsPrivate プロパティ取得するには、最初に Type クラス取得します。そして、その Type から FieldInfo取得します最後にFieldInfo から IsPrivate プロパティ取得します。非パブリック フィールドアクセスするには、BindingFlagsNonPublic設定しGetField メソッドStatic または Instance設定します

使用例使用例

クラスフィールドプライベートかどうかを示す値を返す例を次に示します

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Class [MyClass]
    Private myField As String
    Public myArray() As String
 = {"New York", "New Jersey"}

    Sub New()
        myField = "Microsoft"
    End Sub 'New

    ReadOnly Property GetField() As
 String
        Get
            Return myField
        End Get
    End Property
End Class '[MyClass]


Class FieldInfo_IsPrivate

    Public Shared Sub Main()
        Try
            ' Gets the type of MyClass.
            Dim myType As Type = GetType([MyClass])

            ' Gets the field information of MyClass.
            Dim myFields As FieldInfo() = myType.GetFields((BindingFlags.NonPublic
 Or BindingFlags.Public Or BindingFlags.Instance))

            Console.WriteLine(ControlChars.Cr & "Displaying
 whether the fields of {0} are private or not:" & ControlChars.Cr,
 myType)
            Console.WriteLine() 
            Dim i As Integer
            For i = 0 To myFields.Length -
 1
                ' Check whether the field is private or not. 
                If myFields(i).IsPrivate Then
                    Console.WriteLine("{0} is a private field.",
 myFields(i).Name)
                Else
                    Console.WriteLine("{0} is not a private field.",
 myFields(i).Name)
                End If
            Next i
        Catch e As Exception
            Console.WriteLine("Exception : {0} ",
 e.Message.ToString())
        End Try
    End Sub 'Main
End Class 'FieldInfo_IsPrivate
using System;
using System.Reflection;

class MyClass
{
    private string myField;
    public string[] myArray = new
 string[] {"New York", "New Jersey"};
    MyClass()
    {
        myField = "Microsoft";
    }
    string GetField
    {
        get
        {
            return myField;
        }
    }
}

class FieldInfo_IsPrivate
{
    public static void Main()
    {
        try
        {
            // Gets the type of MyClass.
            Type myType = typeof(MyClass);

            // Gets the field information of MyClass.
            FieldInfo[] myFields = myType.GetFields(BindingFlags.NonPublic
                |BindingFlags.Public
                |BindingFlags.Instance);
      
            Console.WriteLine("\nDisplaying whether the fields of {0} are private
 or not:\n", myType);
            for(int i = 0; i < myFields.Length;
 i++)
            {
                // Check whether the field is private or not. 
                if(myFields[i].IsPrivate)
                    Console.WriteLine("{0} is a private field."
,
 myFields[i].Name);
                else
                    Console.WriteLine("{0} is not a private
 field.", myFields[i].Name);
            }
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception : {0} " , e.Message);
        }
    }
}
using namespace System;
using namespace System::Reflection;

ref class MyClass
{
private:
   String^ myField;

public:
   array<String^>^myArray;
   MyClass()
   {
      myField = "Microsoft";
      array<String^>^s = {"New York","New Jersey"};
      myArray = s;
   }

   property String^ GetField 
   {
      String^ get()
      {
         return myField;
      }
   }
};

int main()
{
   try
   {
      // Gets the type of MyClass.
      Type^ myType = MyClass::typeid;

      // Gets the field information of MyClass.
      array<FieldInfo^>^myFields = myType->GetFields( static_cast<BindingFlags>(BindingFlags::NonPublic
 | BindingFlags::Public | BindingFlags::Instance) );
      Console::WriteLine( "\nDisplaying whether the fields of {0} are private
 or not:\n", myType );
      for ( int i = 0; i < myFields->Length;
 i++ )
      {
         // Check whether the field is private or not. 
         if ( myFields[ i ]->IsPrivate )
                  Console::WriteLine( " {0} is a private
 field.", myFields[ i ]->Name );
         else
                  Console::WriteLine( " {0} is not a private
 field.", myFields[ i ]->Name );
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception : {0} ", e->Message );
   }
}
import System.*;
import System.Reflection.*;

class MyClass
{
    private String myField;
    public String myArray[] = new String[]
 { "New York", "New Jersey" };

    MyClass()
    {
        myField = "Microsoft";
    } //MyClass

    /** @property 
     */
    String get_GetField()
    {
        return myField;
    } // get_GetField
} //MyClass

class FieldInfoIsPrivate
{
    public static void main(String[]
 args)
    {
        try {
            // Gets the type of MyClass.
            Type myType = MyClass.class.ToType();

            // Gets the field information of MyClass.
            FieldInfo myFields[] = myType.GetFields(BindingFlags.NonPublic 
                | BindingFlags.Public | BindingFlags.Instance);
            Console.WriteLine("\nDisplaying whether the fields of {0} are"
 
                + " private or not:\n", myType);
            for (int i = 0; i < myFields.length;
 i++) {
                // Check whether the field is private or not. 
                if (myFields[i].get_IsPrivate()) {
                    Console.WriteLine("{0} is a private field."
,
                        myFields[i].get_Name());
                }
                else {
                    Console.WriteLine("{0} is not a private
 field.", 
                        myFields[i].get_Name());
                }
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception : {0} ", e.get_Message());
        }
    } //main
} //FieldInfoIsPrivate
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「_FieldInfo.IsPrivate プロパティ」の関連用語

_FieldInfo.IsPrivate プロパティのお隣キーワード
検索ランキング

   

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



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

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

©2024 GRAS Group, Inc.RSS