DefaultPropertyAttribute 클래스
구성 요소의 기본 속성을 지정합니다.
네임스페이스: System.ComponentModel
어셈블리: System(system.dll)
구문
‘선언
<AttributeUsageAttribute(AttributeTargets.Class)> _
Public NotInheritable Class DefaultPropertyAttribute
Inherits Attribute
‘사용 방법
Dim instance As DefaultPropertyAttribute
[AttributeUsageAttribute(AttributeTargets.Class)]
public sealed class DefaultPropertyAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class)]
public ref class DefaultPropertyAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class) */
public final class DefaultPropertyAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class)
public final class DefaultPropertyAttribute extends Attribute
설명
Name 속성을 사용하여 기본 속성의 이름을 가져옵니다.
자세한 내용은 특성 개요 및 특성을 사용하여 메타데이터 확장을 참조하십시오.
예제
다음 예제에서는 MyControl
이라는 컨트롤을 정의합니다. 이 클래스는 MyProperty
를 기본 속성으로 지정하는 DefaultPropertyAttribute로 표시됩니다.
<DefaultProperty("MyProperty")> _
Public Class MyControl
Inherits Control
Public Property MyProperty() As Integer
Get
' Insert code here.
Return 0
End Get
Set
' Insert code here.
End Set
End Property
' Insert any additional code.
End Class 'MyControl
[DefaultProperty("MyProperty")]
public class MyControl : Control {
public int MyProperty {
get {
// Insert code here.
return 0;
}
set {
// Insert code here.
}
}
// Insert any additional code.
}
[DefaultProperty("MyProperty")]
ref class MyControl: public Control
{
public:
property int MyProperty
{
int get()
{
// Insert code here.
return 0;
}
void set( int value )
{
// Insert code here.
}
}
// Insert any additional code.
};
/** @attribute DefaultProperty("MyProperty")
*/
public static class MyControl extends Control
{
/** @property
*/
public int get_MyProperty()
{
// Insert code here.
return 0;
} //get_MyProperty
/** @property
*/
public void set_MyProperty(int value)
{
// Insert code here.
} //set_MyProperty
// Insert any additional code.
} //MyControl
다음 예제에서는 MyControl
의 인스턴스를 만듭니다. 그런 다음 클래스에 대한 특성을 가져오고 DefaultPropertyAttribute를 추출한 후 기본 속성의 이름을 출력합니다.
Public Shared Function Main() As Integer
' Creates a new control.
Dim myNewControl As New MyControl()
' Gets the attributes for the collection.
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewControl)
' Prints the name of the default property by retrieving the
' DefaultPropertyAttribute from the AttributeCollection.
Dim myAttribute As DefaultPropertyAttribute = _
CType(attributes(GetType(DefaultPropertyAttribute)), DefaultPropertyAttribute)
Console.WriteLine(("The default property is: " + myAttribute.Name))
Return 0
End Function 'Main
public static int Main() {
// Creates a new control.
MyControl myNewControl = new MyControl();
// Gets the attributes for the collection.
AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewControl);
/* Prints the name of the default property by retrieving the
* DefaultPropertyAttribute from the AttributeCollection. */
DefaultPropertyAttribute myAttribute =
(DefaultPropertyAttribute)attributes[typeof(DefaultPropertyAttribute)];
Console.WriteLine("The default property is: " + myAttribute.Name);
return 0;
}
int main()
{
// Creates a new control.
Form1::MyControl^ myNewControl = gcnew Form1::MyControl;
// Gets the attributes for the collection.
AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewControl );
/* Prints the name of the default property by retrieving the
* DefaultPropertyAttribute from the AttributeCollection. */
DefaultPropertyAttribute^ myAttribute = dynamic_cast<DefaultPropertyAttribute^>(attributes[ DefaultPropertyAttribute::typeid ]);
Console::WriteLine( "The default property is: {0}", myAttribute->Name );
return 0;
}
public static void main(String[] args)
{
// Creates a new control.
MyControl myNewControl = new MyControl();
// Gets the attributes for the collection.
AttributeCollection attributes =
TypeDescriptor.GetAttributes(myNewControl);
/* Prints the name of the default property by retrieving the
DefaultPropertyAttribute from the AttributeCollection.
*/
DefaultPropertyAttribute myAttribute =
(DefaultPropertyAttribute)(attributes.get_Item(
DefaultPropertyAttribute.class.ToType()));
Console.WriteLine("The default property is: "
+ myAttribute.get_Name());
} //main
상속 계층 구조
System.Object
System.Attribute
System.ComponentModel.DefaultPropertyAttribute
스레드로부터의 안전성
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
플랫폼
Windows 98, Windows 2000 SP4, Windows Millennium Edition, 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에서 지원
참고 항목
참조
DefaultPropertyAttribute 멤버
System.ComponentModel 네임스페이스
Attribute