FieldInfo.IsPublic FieldInfo.IsPublic FieldInfo.IsPublic FieldInfo.IsPublic Property

정의

public 필드인지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether the field is public.

public:
 property bool IsPublic { bool get(); };
public bool IsPublic { get; }
member this.IsPublic : bool
Public ReadOnly Property IsPublic As Boolean

속성 값

public 필드이면 true이고, 그렇지 않으면 false입니다.true if this field is public; otherwise, false.

구현

예제

다음 예제에서는 클래스의 필드에 public 또는 private 인지 여부를 나타내는 값을 반환 합니다.The following example returns a value indicating whether or not the field of the class is public or private.

using namespace System;
using namespace System::Reflection;

// Make two fields.
// private
public ref class Myfielda
{
private:
   String^ SomeField;

public:
   Myfielda()
      : SomeField( "private field" )
   {}


   property String^ Field 
   {
      String^ get()
      {
         return SomeField;
      }

   }

};


// public
public ref class Myfieldb
{
public:
   String^ SomeField;
   Myfieldb()
      : SomeField( "public field" )
   {}


   property String^ Field 
   {
      String^ get()
      {
         return SomeField;
      }

   }

};

int main()
{
   Console::WriteLine( "\nReflection.FieldInfo" );
   Myfielda^ myfielda = gcnew Myfielda;
   Myfieldb^ myfieldb = gcnew Myfieldb;
   
   // Get the Type and FieldInfo.
   Type^ MyTypea = Type::GetType( "Myfielda" );
   FieldInfo^ Myfieldinfoa = MyTypea->GetField( "SomeField", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );
   Type^ MyTypeb = Type::GetType( "Myfieldb" );
   FieldInfo^ Myfieldinfob = MyTypeb->GetField( "SomeField" );
   
   // Get and display the IsPublic and IsPrivate property values.
   Console::Write( "\n{0}.", MyTypea->FullName );
   Console::Write( "{0} - ", Myfieldinfoa->Name );
   Console::Write( "{0}", myfielda->Field );
   Console::Write( "\n   IsPublic = {0}", Myfieldinfoa->IsPublic );
   Console::Write( "\n   IsPrivate = {0}", Myfieldinfoa->IsPrivate );
   Console::Write( "\n{0}.", MyTypeb->FullName );
   Console::Write( "{0} - ", Myfieldinfob->Name );
   Console::Write( "{0};", myfieldb->Field );
   Console::Write( "\n   IsPublic = {0}", Myfieldinfob->IsPublic );
   Console::Write( "\n   IsPrivate = {0}", Myfieldinfob->IsPrivate );
   return 0;
}

using System;
using System.Reflection;


 // Make two fields.
public
    class Myfielda // private
{
    private string SomeField = "private field";
    public string Field
    {
        get{return SomeField;}
    }
}

public
    class Myfieldb // public
{
    public string SomeField = "public field";
}
 
public
    class Myfieldinfo
{
    public static int Main()
    {
        Console.WriteLine("\nReflection.FieldInfo");
        Myfielda Myfielda = new Myfielda();
        Myfieldb Myfieldb = new Myfieldb();
  
        // Get the Type and FieldInfo.
        Type MyTypea = typeof(Myfielda);
        FieldInfo Myfieldinfoa = MyTypea.GetField("SomeField", 
            BindingFlags.NonPublic|BindingFlags.Instance);
        Type MyTypeb = typeof(Myfieldb);
        FieldInfo Myfieldinfob = MyTypeb.GetField("SomeField");
  
        // Get and display the IsPublic and IsPrivate property values.
        Console.Write("\n{0}.", MyTypea.FullName);
        Console.Write("{0} - ", Myfieldinfoa.Name);
        Console.Write("{0}", Myfielda.Field);
        Console.Write("\n   IsPublic = {0}", Myfieldinfoa.IsPublic);
        Console.Write("\n   IsPrivate = {0}", Myfieldinfoa.IsPrivate);
  
        Console.Write("\n{0}.", MyTypeb.FullName);
        Console.Write("{0} - ", Myfieldinfob.Name);
        Console.Write("{0};", Myfieldb.SomeField);
        Console.Write("\n   IsPublic = {0}", Myfieldinfob.IsPublic);
        Console.Write("\n   IsPrivate = {0}", Myfieldinfob.IsPrivate);
  
        return 0;
    }
}
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic


' Make two fields.
Public Class Myfielda
    ' Make a private field.
    Private SomeField As String = "private field"

    Public ReadOnly Property Field() As String
        Get
            Return SomeField
        End Get
    End Property
End Class 'Myfielda

Public Class Myfieldb
    ' Make a public field.
    Public SomeField As String = "public field"
End Class 'Myfieldb

Public Class Myfieldinfo

    Public Shared Function Main() As Integer
        Console.WriteLine("Reflection.FieldInfo")
        Console.WriteLine()
        Dim Myfielda As New Myfielda()
        Dim Myfieldb As New Myfieldb()

        ' Get the Type and FieldInfo.
        Dim MyTypea As Type = GetType(Myfielda)
        Dim Myfieldinfoa As FieldInfo = MyTypea.GetField("SomeField", _
            BindingFlags.NonPublic Or BindingFlags.Instance)
        Dim MyTypeb As Type = GetType(Myfieldb)
        Dim Myfieldinfob As FieldInfo = MyTypeb.GetField("SomeField")

        ' Get and display the IsPublic and IsPrivate property values.
        Console.WriteLine("{0}.{1} - {2}", MyTypea.FullName, Myfieldinfoa.Name, _
            Myfielda.Field)
        Console.WriteLine("   IsPublic = {0}", Myfieldinfoa.IsPublic)
        Console.WriteLine("   IsPrivate = {0}", Myfieldinfoa.IsPrivate)
        Console.WriteLine()
        Console.WriteLine("{0}.{1} - {2}", MyTypeb.FullName, Myfieldinfob.Name, _
            Myfieldb.SomeField)
        Console.WriteLine("   IsPublic = {0}", Myfieldinfob.IsPublic)
        Console.WriteLine("   IsPrivate = {0}", Myfieldinfob.IsPrivate)

        Return 0
    End Function 'Main
End Class 'Myfieldinfo

설명

공용 필드는 액세스할 수 있는 어디에서 나 해당 클래스가 표시 됩니다.Public fields are accessible everywhere their corresponding classes are visible.

IsPublic 속성을 설정 하는 경우는 FieldAttributes.Public 특성이 설정 되어 있습니다.The IsPublic property is set when the FieldAttributes.Public attribute is set.

가져오려는 합니다 IsPublic 속성을 먼저 클래스를 가져옵니다 Type합니다.To get the IsPublic property, first get the class Type. Type, 가져오기는 FieldInfo합니다.From the Type, get the FieldInfo. FieldInfo, 가져오기는 IsPublic 속성입니다.From the FieldInfo, get the IsPublic property. 보호 된 필드를 public이 아닌 경우 언제 든 지 액세스할 수 없습니다.If the field is other than public, it is protected and cannot be readily accessed. Public이 아닌 필드에 액세스 하려면 설정 합니다 BindingFlagsNonPublic를 지정 BindingFlags.Instance 또는 BindingFlags.Static에 대 한 사용를 GetField 메서드.To access a nonpublic field, set the BindingFlags to NonPublic, specify either BindingFlags.Instance or BindingFlags.Static, and use this for the GetField method.

적용 대상

추가 정보