DefaultValueAttribute 클래스

정의

속성의 기본값을 지정합니다.

public ref class DefaultValueAttribute : Attribute
public ref class DefaultValueAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public class DefaultValueAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class DefaultValueAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type DefaultValueAttribute = class
    inherit Attribute
Public Class DefaultValueAttribute
Inherits Attribute
Public NotInheritable Class DefaultValueAttribute
Inherits Attribute
상속
DefaultValueAttribute
특성

예제

다음 예제에서는 의 기본값 MyProperty 을 로 false설정합니다.

private:
   bool _myVal;

public:
   [DefaultValue(false)]
   property bool MyProperty 
   {
      bool get()
      {
         return _myVal;
      }

      void set( bool value )
      {
         _myVal = value;
      }
   }

private bool _myVal = false;

[DefaultValue(false)]
public bool MyProperty
{
    get
    {
        return _myVal;
    }
    set
    {
        _myVal = value;
    }
}

Private _myVar As Boolean = False

<DefaultValue(False)>
Public Property MyProperty() As Boolean
    Get
        Return _myVar
    End Get
    Set
        _myVar = Value
    End Set
End Property

다음 예제에서는 의 기본값을 확인합니다 MyProperty. 먼저 코드를 가져옵니다는 PropertyDescriptorCollection 개체에 대 한 모든 속성을 사용 하 여 합니다. 다음으로 인덱스는 PropertyDescriptorCollection 가져오려고 MyProperty합니다. 그런 다음이 속성에 대 한 특성을 반환 하 고 특성 변수에 저장 합니다.

그런 다음, 에서 을 검색하고 DefaultValueAttributeAttributeCollection콘솔 화면에 이름을 작성하여 기본값을 인쇄합니다.

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyProperty" ]->Attributes;

/* Prints the default value by retrieving the DefaultValueAttribute 
      * from the AttributeCollection. */
DefaultValueAttribute^ myAttribute = dynamic_cast<DefaultValueAttribute^>(attributes[ DefaultValueAttribute::typeid ]);
Console::WriteLine( "The default value is: {0}", myAttribute->Value );
// Gets the attributes for the property.
AttributeCollection attributes =
    TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;

/* Prints the default value by retrieving the DefaultValueAttribute 
 * from the AttributeCollection. */
DefaultValueAttribute myAttribute =
    (DefaultValueAttribute) attributes[typeof(DefaultValueAttribute)];
Console.WriteLine("The default value is: " + myAttribute.Value.ToString());
' Gets the attributes for the property.
Dim attributes As AttributeCollection =
        TypeDescriptor.GetProperties(Me)("MyProperty").Attributes

' Prints the default value by retrieving the DefaultValueAttribute
' from the AttributeCollection. 
Dim myAttribute As DefaultValueAttribute =
        CType(attributes(GetType(DefaultValueAttribute)), DefaultValueAttribute)
Console.WriteLine(("The default value is: " & myAttribute.Value.ToString()))

설명

값을 사용하여 을 DefaultValueAttribute 만들 수 있습니다. 멤버의 기본값은 일반적으로 초기 값입니다. 비주얼 디자이너는 기본값을 사용하여 멤버의 값을 다시 설정할 수 있습니다. 코드 생성기는 기본값을 사용하여 멤버에 대해 코드를 생성해야 하는지 여부를 결정할 수도 있습니다.

참고

DefaultValueAttribute 특성 값으로 멤버를 자동으로 초기화하지 않습니다. 코드에서 초기 값을 설정해야 합니다.

자세한 내용은 특성을 참조하세요.

생성자

DefaultValueAttribute(Boolean)

DefaultValueAttribute 값을 사용하여 Boolean 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(Byte)

8비트 부호 없는 정수를 사용하여 DefaultValueAttribute 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(Char)

유니코드 문자를 사용하여 DefaultValueAttribute 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(Double)

배정밀도 부동 소수점 숫자를 사용하여 DefaultValueAttribute 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(Int16)

16비트 부호 있는 정수를 사용하여 DefaultValueAttribute 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(Int32)

32비트 부호 있는 정수를 사용하여 DefaultValueAttribute 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(Int64)

64비트 부호 있는 정수를 사용하여 DefaultValueAttribute 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(Object)

DefaultValueAttribute 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(SByte)

DefaultValueAttribute 값을 사용하여 SByte 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(Single)

단정밀도 부동 소수점 숫자를 사용하여 DefaultValueAttribute 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(String)

DefaultValueAttribute을 사용하여 String 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(Type, String)

지정된 값을 지정된 형식으로 변환하고 고정 문화권을 번역 컨텍스트로 사용하여 DefaultValueAttribute 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(UInt16)

DefaultValueAttribute 값을 사용하여 UInt16 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(UInt32)

DefaultValueAttribute 값을 사용하여 UInt32 클래스의 새 인스턴스를 초기화합니다.

DefaultValueAttribute(UInt64)

DefaultValueAttribute 값을 사용하여 UInt64 클래스의 새 인스턴스를 초기화합니다.

속성

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)
Value

이 특성이 바인딩될 속성의 기본값을 가져옵니다.

메서드

Equals(Object)

주어진 개체의 값이 현재 DefaultValueAttribute와 같은지 여부를 반환합니다.

GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
SetValue(Object)

이 특성이 바인딩될 속성의 기본값을 설정합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상

추가 정보