다음을 통해 공유


FieldInfo.IsStatic 속성

정적 필드인지 여부를 나타내는 값을 가져옵니다.

네임스페이스: System.Reflection
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public ReadOnly Property IsStatic As Boolean
‘사용 방법
Dim instance As FieldInfo
Dim value As Boolean

value = instance.IsStatic
public bool IsStatic { get; }
public:
virtual property bool IsStatic {
    bool get () sealed;
}
/** @property */
public final boolean get_IsStatic ()
public final function get IsStatic () : boolean

속성 값

이 필드가 정적 필드이면 true이고, 그렇지 않으면 false입니다.

설명

정적 필드이면 필드의 복사본 중 하나를 해당 형식의 모든 인스턴스에서 공유합니다.

FieldAttributes.Static 특성이 설정될 때 IsStatic 속성이 설정됩니다.

IsStatic 속성을 가져오려면 먼저 Type 클래스를 가져옵니다. Type에서 FieldInfo를 가져옵니다. FieldInfo에서 IsStatic 속성을 가져옵니다. public이 아닌 필드에 액세스하려면 GetField 메서드에서 BindingFlagsNonPublic으로 설정하고 액세스 가능성을 Instance 또는 Static으로 설정합니다.

예제

다음 예제에서는 지정된 필드가 static인지 여부를 확인하고 그 결과를 표시합니다.

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

' Make two fields.
Public Class Myfielda
    Private m_field As String = "A private field"

    Public Property Field() As String
        Get
            Return m_field
        End Get
        Set(ByVal Value As String)
            If m_field <> value Then
                m_field = value
            End If
        End Set
    End Property
End Class

Public Class Myfieldb
    Private Shared m_field As String = "B private static field"

    Public Property Field() As String
        Get
            Return m_field
        End Get
        Set(ByVal Value As String)
            If m_field <> value Then
                m_field = value
            End If
        End Set
    End Property
End Class

Public Class Myfieldinfo

    Public Shared Sub Main()
        Console.WriteLine()
        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("m_field", BindingFlags.NonPublic Or BindingFlags.Instance)
        Dim MyTypeb As Type = GetType(Myfieldb)
        Dim Myfieldinfob As FieldInfo = _
           MyTypeb.GetField("m_field", BindingFlags.NonPublic Or BindingFlags.Static)

        ' For the first field, get and display the name, field, and IsStatic property value.
        Console.WriteLine("{0} - {1}; IsStatic - {2}", MyTypea.FullName, Myfieldinfoa.GetValue(Myfielda), Myfieldinfoa.IsStatic)

        ' For the second field, get and display the name, field, and IsStatic property value.
        Console.WriteLine("{0} - {1}; IsStatic - {2}", MyTypeb.FullName, Myfieldinfob.GetValue(Myfieldb), Myfieldinfob.IsStatic)

    End Sub
End Class
using System;
using System.Reflection;

 // Make two fields.
public class Myfielda
{
    private string field = "A private field";
    public string Field
    {
        get{return field;}
        set{if(field!=value){field=value;}}
    }
}
public class Myfieldb
{
    static string field = "B private static field";
    public string Field 
    {
        get{return field;}
        set{if(field!=value){field=value;}}
    }
}
  
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("field", BindingFlags.NonPublic|BindingFlags.Instance);
        Type MyTypeb = typeof(Myfieldb);
        FieldInfo Myfieldinfob = MyTypeb.GetField("field", BindingFlags.NonPublic|BindingFlags.Static);
  
        // For the first field, get and display the name, field, and IsStatic property value.
        Console.Write("\n{0} - ", MyTypea.FullName);
        Console.Write("{0}; ", Myfieldinfoa.GetValue(Myfielda));
        Console.Write("IsStatic - {0}", Myfieldinfoa.IsStatic);
  
        // For the second field get and display the name, field, and IsStatic property value.
        Console.Write("\n{0} - ", MyTypeb.FullName);
        Console.Write("{0}; ", Myfieldinfob.GetValue(Myfieldb));
        Console.Write("IsStatic - {0}", Myfieldinfob.IsStatic);
  
        return 0;
    }
}
using namespace System;
using namespace System::Reflection;

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

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


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

      void set( String^ value )
      {
         if ( field != value )
         {
            field = value;
         }
      }

   }

};

public ref class Myfieldb
{
private:
   static String^ field = "B static field";

public:

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

      void set( String^ value )
      {
         if ( field != value )
         {
            field = value;
         }
      }

   }

};

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( "field", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );
   Type^ MyTypeb = Type::GetType( "Myfieldb" );
   FieldInfo^ Myfieldinfob = MyTypeb->GetField( "field", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Static) );
   
   // For the first field, get and display the name, field, and IsStatic property value.
   Console::Write( "\n{0} - ", MyTypea->FullName );
   Console::Write( "{0}; ", Myfieldinfoa->GetValue( myfielda ) );
   Console::Write( "IsStatic - {0}", Myfieldinfoa->IsStatic );
   
   // For the second field get and display the name, field, and IsStatic property value.
   Console::Write( "\n{0} - ", MyTypeb->FullName );
   Console::Write( "{0}; ", Myfieldinfob->GetValue( myfieldb ) );
   Console::Write( "IsStatic - {0}", Myfieldinfob->IsStatic );
   return 0;
}
import System.*;
import System.Reflection.*;

// Make two fields.
public class MyFielda
{
    private String field = "A private field";

    /** @property 
     */
    public String get_Field()
    {
        return field;
    } //get_Field

    /** @property 
     */
    public void set_Field(String value)
    {
        if (!(field.Equals(value))) {
            field = value;
        }
    } //set_Field
} //MyFielda

public class MyFieldb
{
    private static String field = "B static field";

    /** @property 
     */
    public String get_Field()
    {
        return field;
    } //get_Field

    /** @property 
     */
    public void set_Field(String value)
    {
        if (!(field.Equals(value))) {
            field = value;
        }
    } //set_Field
} //MyFieldb

public class MyFieldInfo
{
    public static void main(String[] args)
    {
        Console.WriteLine("\nReflection.FieldInfo");
        MyFielda myFielda = new MyFielda();
        MyFieldb myFieldb = new MyFieldb();

        // Get the Type and FieldInfo.
        Type myTypea = Type.GetType("MyFielda");
        FieldInfo myFieldInfoa = myTypea.GetField("field", 
            BindingFlags.NonPublic | BindingFlags.Instance);
        Type myTypeb = Type.GetType("MyFieldb");
        FieldInfo myFieldInfob = myTypeb.GetField("field", 
            BindingFlags.NonPublic | BindingFlags.Static);

        // For the first field, get and display the name, field, and 
        // IsStatic property value.
        Console.Write("\n{0} - ", myTypea.get_FullName());
        Console.Write("{0}; ", myFieldInfoa.GetValue(myFielda));
        Console.Write("IsStatic - {0}", 
            System.Convert.ToString(myFieldInfoa.get_IsStatic()));

        // For the second field get and display the name, field, and 
        // IsStatic property value.
        Console.Write("\n{0} - ", myTypeb.get_FullName());
        Console.Write("{0}; ", myFieldInfob.GetValue(myFieldb));
        Console.Write("IsStatic - {0}", 
            System.Convert.ToString(myFieldInfob.get_IsStatic()));
    } //main
} //MyFieldInfo
//Make two fields.
public class Myfielda
{
   private var field : String = "A private field";
   public function get Field() : String {
       return field;
   }
   
   public function set Field(value : String) {
       if(field!=value)field=value;
   }
}
public class Myfieldb
{
   private static var field : String = "B static field";
   public static function get Field() : String  {
       return field;
   }
   public static function set Field(value : String) {
       if(field!=value) field=value;
   }
}
 
public class Myfieldinfo
{
   public static function Main() : void
   {
      Console.WriteLine("\nReflection.FieldInfo");
      var myfielda : Myfielda = new Myfielda();
      var myfieldb : Myfieldb = new Myfieldb();
 
      //Get the Type and FieldInfo.
      var MyTypea : Type = Type.GetType("Myfielda");
      var Myfieldinfoa : FieldInfo = MyTypea.GetField("field", BindingFlags.NonPublic|BindingFlags.Instance);
      var MyTypeb : Type = Type.GetType("Myfieldb");
      var Myfieldinfob : FieldInfo = MyTypeb.GetField("field", BindingFlags.NonPublic|BindingFlags.Static);
 
      //For the first field, get and display the name, field, and IsStatic.
      Console.Write("\n{0} - ", MyTypea.FullName);
      Console.Write("{0}; ", Myfieldinfoa.GetValue(myfielda));
      Console.Write("IsStatic - {0}", Myfieldinfoa.IsStatic);
 
      //For the second field get and display the name, field, and IsStatic.
      Console.Write("\n{0} - ", MyTypeb.FullName);
      Console.Write("{0}; ", Myfieldinfob.GetValue(myfieldb));
      Console.Write("IsStatic - {0}", Myfieldinfob.IsStatic);
   }
}
Myfieldinfo.Main();

이 코드는 다음과 같이 출력됩니다.

Reflection.FieldInfo

Myfielda - A private field; IsStatic - False

Myfieldb - B static field; IsStatic - True

플랫폼

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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

FieldInfo 클래스
FieldInfo 멤버
System.Reflection 네임스페이스
FieldAttributes 열거형
GetField
Type