다음을 통해 공유


PropertyAttributes 열거형

속성과 관련될 수 있는 특성을 정의합니다. 이러한 특성 값은 corhdr.h에 정의되어 있습니다.

이 열거형에는 멤버 값를 비트로 조합할 수 있는 FlagsAttribute 특성이 있습니다.

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

구문

‘선언
<SerializableAttribute> _
<FlagsAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration PropertyAttributes
‘사용 방법
Dim instance As PropertyAttributes
[SerializableAttribute] 
[FlagsAttribute] 
[ComVisibleAttribute(true)] 
public enum PropertyAttributes
[SerializableAttribute] 
[FlagsAttribute] 
[ComVisibleAttribute(true)] 
public enum class PropertyAttributes
/** @attribute SerializableAttribute() */ 
/** @attribute FlagsAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum PropertyAttributes
SerializableAttribute 
FlagsAttribute 
ComVisibleAttribute(true) 
public enum PropertyAttributes

멤버

  멤버 이름 설명
Supported by the .NET Compact Framework HasDefault 속성이 기본값을 갖도록 지정합니다. 
Supported by the .NET Compact Framework None 속성과 관련된 특성이 없도록 지정합니다. 
Supported by the .NET Compact Framework Reserved2 예약되었습니다.  
Supported by the .NET Compact Framework Reserved3 예약되었습니다.  
Supported by the .NET Compact Framework Reserved4 예약되었습니다.  
Supported by the .NET Compact Framework ReservedMask 런타임 전용으로 예약된 플래그를 지정합니다. 
Supported by the .NET Compact Framework RTSpecialName 메타데이터 내부 API에서 이름 인코딩을 확인하도록 지정합니다. 
Supported by the .NET Compact Framework SpecialName 속성의 특수성을 설명하는 이름을 사용하여 속성을 지정합니다. 

설명

PropertyAttributes를 가져오려면 먼저 Type 클래스를 가져옵니다. Type에서 PropertyInfo를 가져옵니다. PropertyInfo에서 Attributes를 가져옵니다.

열거형 값은 메서드에 구현된 특성의 비트 OR를 나타내는 숫자입니다.

예제

다음 예제에서는 세 개의 속성을 작성하고 PropertyAttributes 열거형 값을 표시합니다. 읽기 전용 속성에는 setter가 없으므로 Caption = statement를 사용하여 변경할 수 없습니다.

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

' Make three properties, one read-write, one default,
' and one read-only. 
Public Class Aproperty
    ' Define a read-write property.
    Private myCaption As String = "A Default caption"

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

Public Class Bproperty
    ' Define a default property.
    Private myCaption As String = "B Default caption"

    Default Public ReadOnly Property Item(ByVal index As Integer) As String
        Get
            Return "1"
        End Get
    End Property

    Public Property Caption() As String

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

Public Class Cproperty
    ' Define a read-only property.
    Private myCaption As String = "C Default caption"

    Public ReadOnly Property Caption() As String
        Get
            Return myCaption
        End Get
        'No setting is allowed because this property is read-only.
    End Property
End Class


Class propertyattributesenum

    Public Shared Function Main() As Integer
        Console.WriteLine(ControlChars.CrLf & "Reflection.PropertyAttributes")

        ' Determine whether a property exists, and change its value.
        Dim Mypropertya As New Aproperty()
        Dim Mypropertyb As New Bproperty()
        Dim Mypropertyc As New Cproperty()

        Console.Write(ControlChars.CrLf & "1. Mypropertya.Caption = " & _
           Mypropertya.Caption)

        Console.Write(ControlChars.CrLf & "1. Mypropertyb.Caption = " & _
           Mypropertyb.Caption)

        Console.Write(ControlChars.CrLf & "1. Mypropertyc.Caption = " & _
           Mypropertyc.Caption)

        ' Only Mypropertya can be changed because Mypropertyb is read-only.
        Mypropertya.Caption = "A- This is changed."
        Mypropertyb.Caption = "B- This is changed."
        ' Note that Mypropertyc is not changed, because it is read-only.
        Console.Write(ControlChars.CrLf & ControlChars.CrLf & _
           "2. Mypropertya.Caption = " & Mypropertya.Caption)

        Console.Write(ControlChars.CrLf & "2.Mypropertyb.Caption = " & _
           Mypropertyb.Caption)

        Console.Write(ControlChars.CrLf + "2. Mypropertyc.Caption = " & _
           Mypropertyc.Caption)

        ' Get the PropertyAttributes Enumeration of the property.
        ' Get the type.
        Dim MyTypea As Type = Type.GetType("Aproperty")
        Dim MyTypeb As Type = Type.GetType("Bproperty")
        Dim MyTypec As Type = Type.GetType("Cproperty")

        ' Get the property attributes.
        Dim Mypropertyinfoa As PropertyInfo = MyTypea.GetProperty("Caption")
        Dim Myattributesa As PropertyAttributes = Mypropertyinfoa.Attributes
        Dim Mypropertyinfob As PropertyInfo = MyTypeb.GetProperty("Item")
        Dim Myattributesb As PropertyAttributes = Mypropertyinfob.Attributes
        Dim Mypropertyinfoc As PropertyInfo = MyTypec.GetProperty("Caption")
        Dim Myattributesc As PropertyAttributes = Mypropertyinfoc.Attributes

        ' Display the property attributes value.
        Console.Write(ControlChars.CrLf & ControlChars.CrLf & "a- " & _
           Myattributesa.ToString())

        Console.Write(ControlChars.CrLf & "b-" & Myattributesb.ToString())

        Console.Write(ControlChars.CrLf & "c- " & Myattributesc.ToString())
        Return 0
    End Function
End Class
using System;
using System.Reflection;
 
 // Define three properties: one read-write, one default,
 // and one read only. 
public class Aproperty  
    // Define a read-write property.
{
    private string caption = "A Default caption";
    public string Caption
    {
        get{return caption;}
        set
        {
            if (caption != value){caption = value;}
        }
    }
}
public class Bproperty  
    // Define a default property.
{
    private string caption  = "B Default caption";
    public string this [int index]
    {
        get {return "1";}
    }
    public string Caption
    {
  
        get{return caption;}
        set
        {
            if (caption != value){caption = value;}
        }
    }
}
public class Cproperty  
    // Define a read-only property.
{
    private string caption = "C Default caption";
    public string Caption
    {
        get{return caption;}
        // No setting is allowed, because this is a read-only property.
    }
}
  
class propertyattributesenum
{
    public static int Main(string[] args)
    {
        Console.WriteLine("\nReflection.PropertyAttributes");
  
        // Determine whether a property exists, and change its value.
        Aproperty Mypropertya = new Aproperty();
        Bproperty Mypropertyb = new Bproperty();
        Cproperty Mypropertyc = new Cproperty();
  
      
        Console.Write("\n1. Mypropertya.Caption = " + Mypropertya.Caption );
      
        Console.Write("\n1. Mypropertyb.Caption = " + Mypropertyb.Caption );
      
        Console.Write("\n1. Mypropertyc.Caption = " + Mypropertyc.Caption );
  
        // Only Mypropertya can be changed, as Mypropertyb is read-only.
        Mypropertya.Caption = "A- This is changed.";
        Mypropertyb.Caption = "B- This is changed.";
        // Note that Mypropertyc is not changed because it is read only
  
        Console.Write("\n\n2. Mypropertya.Caption = " + Mypropertya.Caption );
  
        Console.Write("\n2.Mypropertyb.Caption = " + Mypropertyb.Caption );
 
        Console.Write("\n2. Mypropertyc.Caption = " + Mypropertyc.Caption );
  
        // Get the PropertyAttributes enumeration of the property.
        // Get the type.
        Type MyTypea = Type.GetType("Aproperty");
        Type MyTypeb = Type.GetType("Bproperty");
        Type MyTypec = Type.GetType("Cproperty");
  
        // Get the property attributes.
        PropertyInfo Mypropertyinfoa = MyTypea.GetProperty("Caption");
        PropertyAttributes Myattributesa = Mypropertyinfoa.Attributes;
        PropertyInfo Mypropertyinfob = MyTypeb.GetProperty("Item");
        PropertyAttributes Myattributesb = Mypropertyinfob.Attributes;
        PropertyInfo Mypropertyinfoc = MyTypec.GetProperty("Caption");
        PropertyAttributes Myattributesc = Mypropertyinfoc.Attributes;
  
        // Display the property attributes value.
      
        Console.Write("\n\na- " + Myattributesa.ToString());
  
        Console.Write("\nb-" + Myattributesb.ToString());
      
        Console.Write("\nc- " + Myattributesc.ToString());
        return 0;
    }
}
using namespace System;
using namespace System::Reflection;

// Define three properties: one read-write, one default,
// and one read only. 
// Define a read-write property.
public ref class Aproperty
{
private:
   String^ caption;

public:
   Aproperty()
      : caption( "A Default caption" )
   {}


   property String^ Caption 
   {
      String^ get()
      {
         return caption;
      }

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

   }

};


// Define a default property.
public ref class Bproperty
{
private:
   String^ caption;

public:
   Bproperty()
      : caption( "B Default caption" )
   {}

public:
   property String^ Item
   {
      String^ get()
      {
         return "1";
      }

   }

   property String^ Caption 
   {
      String^ get()
      {
         return caption;
      }

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

   }

};


// Define a read-only property.
public ref class Cproperty
{
private:
   String^ caption;

public:
   Cproperty()
      : caption( "C Default caption" )
   {}


   property String^ Caption 
   {
      String^ get()
      {
         return caption;
      }

   }

};

int main()
{
   Console::WriteLine( "\nReflection.PropertyAttributes" );
   
   // Determine whether a property exists, and change its value.
   Aproperty^ Mypropertya = gcnew Aproperty;
   Bproperty^ Mypropertyb = gcnew Bproperty;
   Cproperty^ Mypropertyc = gcnew Cproperty;
   Console::Write( "\n1. Mypropertya->Caption = {0}", Mypropertya->Caption );
   Console::Write( "\n1. Mypropertyb->Caption = {0}", Mypropertyb->Caption );
   Console::Write( "\n1. Mypropertyc->Caption = {0}", Mypropertyc->Caption );
   
   // Only Mypropertya can be changed, as Mypropertyb is read-only.
   Mypropertya->Caption = "A- This is changed.";
   Mypropertyb->Caption = "B- This is changed.";
   
   // Note that Mypropertyc is not changed because it is read only
   Console::Write( "\n\n2. Mypropertya->Caption = {0}", Mypropertya->Caption );
   Console::Write( "\n2.Mypropertyb->Caption = {0}", Mypropertyb->Caption );
   Console::Write( "\n2. Mypropertyc->Caption = {0}", Mypropertyc->Caption );
   
   // Get the PropertyAttributes enumeration of the property.
   // Get the type.
   Type^ MyTypea = Type::GetType( "Aproperty" );
   Type^ MyTypeb = Type::GetType( "Bproperty" );
   Type^ MyTypec = Type::GetType( "Cproperty" );
   
   // Get the property attributes.
   PropertyInfo^ Mypropertyinfoa = MyTypea->GetProperty( "Caption" );
   PropertyAttributes Myattributesa = Mypropertyinfoa->Attributes;
   PropertyInfo^ Mypropertyinfob = MyTypeb->GetProperty( "Item" );
   PropertyAttributes Myattributesb = Mypropertyinfob->Attributes;
   PropertyInfo^ Mypropertyinfoc = MyTypec->GetProperty( "Caption" );
   PropertyAttributes Myattributesc = Mypropertyinfoc->Attributes;
   
   // Display the property attributes value.
   Console::Write( "\n\na- {0}", Myattributesa );
   Console::Write( "\nb-{0}", Myattributesb );
   Console::Write( "\nc- {0}", Myattributesc );
   return 0;
}
import System.*;
import System.Reflection.*;

// Define three properties: one read-write, one default,
// and one read only. 
public class AProperty
{
    // Define a read-write property.
    private String caption = "A Default caption";

    /** @property 
     */
    public String get_Caption()
    {
        return caption ;
    } //get_Caption

    /** @property 
     */
    public void set_Caption(String value)
    {
        if (caption != value) {
            caption = value;
        }
    } //set_Caption
} //AProperty

public class BProperty
{
    // Define a default property.
    private String caption = "B Default caption";

    /** @property 
     */
    public String get_Item(int index)
    {
        return "1" ;
    } //get_Item

    /** @property 
     */
    public String get_Caption()
    {
        return caption ;
    } //get_Caption

    /** @property 
     */
    public void set_Caption (String value)
    {
        if (caption != value) {
            caption = value;
        }
    } //set_Caption
} //BProperty

public class CProperty
{
    // Define a read-only property.
    private String caption = "C Default caption";

    /** @property 
     */
    public String get_Caption()
    {
        return caption ;
        // No setting is allowed, because this is a read-only property.
    } //get_Caption
} //CProperty

class PropertyAttributesEnum
{   
    public static void main(String[] args)
    {
        Console.WriteLine("\nReflection.PropertyAttributes");

        // Determine whether a property exists, and change its value.
        AProperty myPropertyA =  new AProperty();
        BProperty myPropertyB =  new BProperty();
        CProperty myPropertyC =  new CProperty();

        Console.Write(("\n1. Mypropertya.Caption = " 
            + myPropertyA.get_Caption()));
        Console.Write(("\n1. Mypropertyb.Caption = " 
            + myPropertyB.get_Caption()));
        Console.Write(("\n1. Mypropertyc.Caption = " 
            + myPropertyC.get_Caption()));

        // Only myPropertyA can be changed, as myPropertyB is read-only.
        myPropertyA.set_Caption("A- This is changed.");
        myPropertyB.set_Caption("B- This is changed.");
        // Note that myPropertyC is not changed because it is read only
        Console.Write(("\n\n2. Mypropertya.Caption = " 
            + myPropertyA.get_Caption()));
        Console.Write(("\n2.Mypropertyb.Caption = " 
            + myPropertyB.get_Caption()));
        Console.Write(("\n2. Mypropertyc.Caption = " 
            + myPropertyC.get_Caption()));

        // Get the PropertyAttributes enumeration of the property.
        // Get the type.
        Type myTypeA = Type.GetType("AProperty");
        Type myTypeB = Type.GetType("BProperty");
        Type myTypeC = Type.GetType("CProperty");

        // Get the property attributes.
        PropertyInfo myPropertyInfoA = myTypeA.GetProperty("Caption");
        PropertyAttributes myAttributesA = myPropertyInfoA.get_Attributes();
        PropertyInfo myPropertyInfoB = myTypeB.GetProperty("Item");
        PropertyAttributes myAttributesB = myPropertyInfoB.get_Attributes();
        PropertyInfo myPropertyInfoC = myTypeC.GetProperty("Caption");
        PropertyAttributes myAttributesC = myPropertyInfoC.get_Attributes();

        // Display the property attributes value.
        Console.Write(("\n\nA- " + myAttributesA.ToString()));
        Console.Write(("\nB-" + myAttributesB.ToString()));
        Console.Write(("\nC- " + myAttributesC.ToString()));
    } //main
} //PropertyAttributesEnum

플랫폼

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에서 지원

참고 항목

참조

System.Reflection 네임스페이스