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
특성

예제

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

private:
   bool _myVal;

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

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

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. 그런 다음, 이 속성에 대한 특성을 반환하고 특성 변수에 저장합니다.

그런 다음, 이 예제에서는 기본AttributeCollection값을 검색하여 DefaultValueAttribute 콘솔 화면에 이름을 기록합니다.

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

Note

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

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

생성자

Name Description
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 초기화합니다.

속성

Name Description
TypeId

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

(다음에서 상속됨 Attribute)
Value

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

메서드

Name Description
Equals(Object)

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

GetHashCode()

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

GetType()

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

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

파생 클래스에서 재정의되는 경우 이 인스턴스의 값이 파생 클래스의 기본값인지 여부를 나타냅니다.

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

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

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

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

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

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

ToString()

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

(다음에서 상속됨 Object)

명시적 인터페이스 구현

Name Description
_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)

적용 대상

추가 정보