PropertyDescriptor 클래스
정의
클래스의 속성에 대한 추상화를 제공합니다.Provides an abstraction of a property on a class.
public ref class PropertyDescriptor abstract : System::ComponentModel::MemberDescriptor
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class PropertyDescriptor : System.ComponentModel.MemberDescriptor
type PropertyDescriptor = class
inherit MemberDescriptor
Public MustInherit Class PropertyDescriptor
Inherits MemberDescriptor
- 상속
- 파생
- 특성
예제
다음 코드 예제는 예제에 기반을 PropertyDescriptorCollection 클래스입니다.The following code example is built upon the example in the PropertyDescriptorCollection class. 이 정보를 인쇄 합니다 (범주, 설명, 표시 이름) 텍스트 상자에 있는 단추의 텍스트.It prints the information (category, description, display name) of the text of a button in a text box. 가정 button1
및 textbox1
양식의 인스턴스화해야 합니다.It assumes that button1
and textbox1
have been instantiated on a form.
// Creates a new collection and assign it the properties for button1.
PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
// Sets an PropertyDescriptor to the specific property.
System::ComponentModel::PropertyDescriptor^ myProperty = properties->Find( "Text", false );
// Prints the property and the property description.
textBox1->Text = String::Concat( myProperty->DisplayName, "\n" );
textBox1->Text = String::Concat( textBox1->Text, myProperty->Description, "\n" );
textBox1->Text = String::Concat( textBox1->Text, myProperty->Category, "\n" );
// Creates a new collection and assign it the properties for button1.
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);
// Sets an PropertyDescriptor to the specific property.
System.ComponentModel.PropertyDescriptor myProperty = properties.Find("Text", false);
// Prints the property and the property description.
textBox1.Text = myProperty.DisplayName+ '\n' ;
textBox1.Text += myProperty.Description + '\n';
textBox1.Text += myProperty.Category + '\n';
' Creates a new collection and assign it the properties for button1.
Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(Button1)
' Sets an PropertyDescriptor to the specific property.
Dim myProperty As PropertyDescriptor = properties.Find("Text", False)
' Prints the property and the property description.
TextBox1.Text += myProperty.DisplayName & Microsoft.VisualBasic.ControlChars.Cr
TextBox1.Text += myProperty.Description & Microsoft.VisualBasic.ControlChars.Cr
TextBox1.Text += myProperty.Category & Microsoft.VisualBasic.ControlChars.Cr
다음 코드 예제에는 읽기 전용 속성 래퍼를 제공 하는 사용자 지정 속성 설명자를 구현 하는 방법을 보여 줍니다.The following code example shows how to implement a custom property descriptor that provides a read-only wrapper around a property. 합니다 SerializeReadOnlyPropertyDescriptor
사용자 지정 디자이너에서 컨트롤에 대 한 읽기 전용 속성 설명자를 제공 하는 데 사용 됩니다 Size 속성입니다.The SerializeReadOnlyPropertyDescriptor
is used in a custom designer to provide a read-only property descriptor for the control's Size property.
using System;
using System.Collections;
using System.ComponentModel;
using System.Text;
namespace ReadOnlyPropertyDescriptorTest
{
// The SerializeReadOnlyPropertyDescriptor shows how to implement a
// custom property descriptor. It provides a read-only wrapper
// around the specified PropertyDescriptor.
internal sealed class SerializeReadOnlyPropertyDescriptor : PropertyDescriptor
{
private PropertyDescriptor _pd = null;
public SerializeReadOnlyPropertyDescriptor(PropertyDescriptor pd)
: base(pd)
{
this._pd = pd;
}
public override AttributeCollection Attributes
{
get
{
return( AppendAttributeCollection(
this._pd.Attributes,
ReadOnlyAttribute.Yes) );
}
}
protected override void FillAttributes(IList attributeList)
{
attributeList.Add(ReadOnlyAttribute.Yes);
}
public override Type ComponentType
{
get
{
return this._pd.ComponentType;
}
}
// The type converter for this property.
// A translator can overwrite with its own converter.
public override TypeConverter Converter
{
get
{
return this._pd.Converter;
}
}
// Returns the property editor
// A translator can overwrite with its own editor.
public override object GetEditor(Type editorBaseType)
{
return this._pd.GetEditor(editorBaseType);
}
// Specifies the property is read only.
public override bool IsReadOnly
{
get
{
return true;
}
}
public override Type PropertyType
{
get
{
return this._pd.PropertyType;
}
}
public override bool CanResetValue(object component)
{
return this._pd.CanResetValue(component);
}
public override object GetValue(object component)
{
return this._pd.GetValue(component);
}
public override void ResetValue(object component)
{
this._pd.ResetValue(component);
}
public override void SetValue(object component, object val)
{
this._pd.SetValue(component, val);
}
// Determines whether a value should be serialized.
public override bool ShouldSerializeValue(object component)
{
bool result = this._pd.ShouldSerializeValue(component);
if (!result)
{
DefaultValueAttribute dva = (DefaultValueAttribute)_pd.Attributes[typeof(DefaultValueAttribute)];
if (dva != null)
{
result = !Object.Equals(this._pd.GetValue(component), dva.Value);
}
else
{
result = true;
}
}
return result;
}
// The following Utility methods create a new AttributeCollection
// by appending the specified attributes to an existing collection.
static public AttributeCollection AppendAttributeCollection(
AttributeCollection existing,
params Attribute[] newAttrs)
{
return new AttributeCollection(AppendAttributes(existing, newAttrs));
}
static public Attribute[] AppendAttributes(
AttributeCollection existing,
params Attribute[] newAttrs)
{
if (existing == null)
{
throw new ArgumentNullException(nameof(existing));
}
newAttrs ??= new Attribute[0];
Attribute[] attributes;
Attribute[] newArray = new Attribute[existing.Count + newAttrs.Length];
int actualCount = existing.Count;
existing.CopyTo(newArray, 0);
for (int idx = 0; idx < newAttrs.Length; idx++)
{
if (newAttrs[idx] == null)
{
throw new ArgumentNullException("newAttrs");
}
// Check if this attribute is already in the existing
// array. If it is, replace it.
bool match = false;
for (int existingIdx = 0; existingIdx < existing.Count; existingIdx++)
{
if (newArray[existingIdx].TypeId.Equals(newAttrs[idx].TypeId))
{
match = true;
newArray[existingIdx] = newAttrs[idx];
break;
}
}
if (!match)
{
newArray[actualCount++] = newAttrs[idx];
}
}
// If some attributes were collapsed, create a new array.
if (actualCount < newArray.Length)
{
attributes = new Attribute[actualCount];
Array.Copy(newArray, 0, attributes, 0, actualCount);
}
else
{
attributes = newArray;
}
return attributes;
}
}
}
Imports System.Collections
Imports System.ComponentModel
Imports System.Text
' The SerializeReadOnlyPropertyDescriptor shows how to implement a
' custom property descriptor. It provides a read-only wrapper
' around the specified PropertyDescriptor.
Friend NotInheritable Class SerializeReadOnlyPropertyDescriptor
Inherits PropertyDescriptor
Private _pd As PropertyDescriptor = Nothing
Public Sub New(ByVal pd As PropertyDescriptor)
MyBase.New(pd)
Me._pd = pd
End Sub
Public Overrides ReadOnly Property Attributes() As AttributeCollection
Get
Return AppendAttributeCollection(Me._pd.Attributes, ReadOnlyAttribute.Yes)
End Get
End Property
Protected Overrides Sub FillAttributes(ByVal attributeList As IList)
attributeList.Add(ReadOnlyAttribute.Yes)
End Sub
Public Overrides ReadOnly Property ComponentType() As Type
Get
Return Me._pd.ComponentType
End Get
End Property
' The type converter for this property.
' A translator can overwrite with its own converter.
Public Overrides ReadOnly Property Converter() As TypeConverter
Get
Return Me._pd.Converter
End Get
End Property
' Returns the property editor
' A translator can overwrite with its own editor.
Public Overrides Function GetEditor(ByVal editorBaseType As Type) As Object
Return Me._pd.GetEditor(editorBaseType)
End Function
' Specifies the property is read only.
Public Overrides ReadOnly Property IsReadOnly() As Boolean
Get
Return True
End Get
End Property
Public Overrides ReadOnly Property PropertyType() As Type
Get
Return Me._pd.PropertyType
End Get
End Property
Public Overrides Function CanResetValue(ByVal component As Object) As Boolean
Return Me._pd.CanResetValue(component)
End Function
Public Overrides Function GetValue(ByVal component As Object) As Object
Return Me._pd.GetValue(component)
End Function
Public Overrides Sub ResetValue(ByVal component As Object)
Me._pd.ResetValue(component)
End Sub
Public Overrides Sub SetValue(ByVal component As Object, ByVal val As Object)
Me._pd.SetValue(component, val)
End Sub
' Determines whether a value should be serialized.
Public Overrides Function ShouldSerializeValue(ByVal component As Object) As Boolean
Dim result As Boolean = Me._pd.ShouldSerializeValue(component)
If Not result Then
Dim dva As DefaultValueAttribute = _
CType(_pd.Attributes(GetType(DefaultValueAttribute)), DefaultValueAttribute)
If Not (dva Is Nothing) Then
result = Not [Object].Equals(Me._pd.GetValue(component), dva.Value)
Else
result = True
End If
End If
Return result
End Function
' The following Utility methods create a new AttributeCollection
' by appending the specified attributes to an existing collection.
Public Shared Function AppendAttributeCollection( _
ByVal existing As AttributeCollection, _
ByVal ParamArray newAttrs() As Attribute) As AttributeCollection
Return New AttributeCollection(AppendAttributes(existing, newAttrs))
End Function
Public Shared Function AppendAttributes( _
ByVal existing As AttributeCollection, _
ByVal ParamArray newAttrs() As Attribute) As Attribute()
If existing Is Nothing Then
Throw New ArgumentNullException("existing")
End If
If newAttrs Is Nothing Then
newAttrs = New Attribute(-1) {}
End If
Dim attributes() As Attribute
Dim newArray(existing.Count + newAttrs.Length) As Attribute
Dim actualCount As Integer = existing.Count
existing.CopyTo(newArray, 0)
Dim idx As Integer
For idx = 0 To newAttrs.Length
If newAttrs(idx) Is Nothing Then
Throw New ArgumentNullException("newAttrs")
End If
' Check if this attribute is already in the existing
' array. If it is, replace it.
Dim match As Boolean = False
Dim existingIdx As Integer
For existingIdx = 0 To existing.Count - 1
If newArray(existingIdx).TypeId.Equals(newAttrs(idx).TypeId) Then
match = True
newArray(existingIdx) = newAttrs(idx)
Exit For
End If
Next existingIdx
If Not match Then
actualCount += 1
newArray(actualCount) = newAttrs(idx)
End If
Next idx
' If some attributes were collapsed, create a new array.
If actualCount < newArray.Length Then
attributes = New Attribute(actualCount) {}
Array.Copy(newArray, 0, attributes, 0, actualCount)
Else
attributes = newArray
End If
Return attributes
End Function
End Class
다음 코드 예제에 사용 하는 방법을 보여 줍니다는 SerializeReadOnlyPropertyDescriptor
사용자 지정 디자이너에서입니다.The following code examples show how to use the SerializeReadOnlyPropertyDescriptor
in a custom designer.
using System;
using System.Collections;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms.Design;
namespace ReadOnlyPropertyDescriptorTest
{
class DemoControlDesigner : ControlDesigner
{
// The PostFilterProperties method replaces the control's
// Size property with a read-only Size property by using
// the SerializeReadOnlyPropertyDescriptor class.
protected override void PostFilterProperties(IDictionary properties)
{
if (properties.Contains("Size"))
{
PropertyDescriptor original = properties["Size"] as PropertyDescriptor;
SerializeReadOnlyPropertyDescriptor readOnlyDescriptor =
new SerializeReadOnlyPropertyDescriptor(original);
properties["Size"] = readOnlyDescriptor;
}
base.PostFilterProperties(properties);
}
}
}
Imports System.Collections
Imports System.ComponentModel
Imports System.Text
Imports System.Windows.Forms.Design
Class DemoControlDesigner
Inherits ControlDesigner
' The PostFilterProperties method replaces the control's
' Size property with a read-only Size property by using
' the SerializeReadOnlyPropertyDescriptor class.
Protected Overrides Sub PostFilterProperties(ByVal properties As IDictionary)
If properties.Contains("Size") Then
Dim original As PropertyDescriptor = properties("Size")
Dim readOnlyDescriptor As New SerializeReadOnlyPropertyDescriptor(original)
properties("Size") = readOnlyDescriptor
End If
MyBase.PostFilterProperties(properties)
End Sub
End Class
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace ReadOnlyPropertyDescriptorTest
{
[Designer(typeof(DemoControlDesigner))]
public class DemoControl : Control
{
public DemoControl()
{
}
}
}
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Text
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
<Designer(GetType(DemoControlDesigner))> _
Public Class DemoControl
Inherits Control
Public Sub New()
End Sub
End Class
설명
속성에 대 한 설명을 이름, 특성, 속성 연결 되어 있는 구성 요소 클래스 및 속성의 형식으로 구성 됩니다.A description of a property consists of a name, its attributes, the component class that the property is associated with, and the type of the property.
PropertyDescriptor 다음 속성 및 메서드를 제공 합니다.PropertyDescriptor provides the following properties and methods:
Converter 포함 된 TypeConverter 이 속성에 대 한 합니다.Converter contains the TypeConverter for this property.
IsLocalizable 이 속성을 지역화 해야 하는지 여부를 나타냅니다.IsLocalizable indicates whether this property should be localized.
GetEditor 지정 된 형식의 편집기를 반환합니다.GetEditor returns an editor of the specified type.
PropertyDescriptor 또한 다음을 제공 abstract
속성 및 메서드:PropertyDescriptor also provides the following abstract
properties and methods:
ComponentType 이 속성이 바인딩된 구성 요소의 유형을 포함 합니다.ComponentType contains the type of component this property is bound to.
IsReadOnly 이 속성이 읽기 전용인 지 여부를 나타냅니다.IsReadOnly indicates whether this property is read-only.
PropertyType 속성의 형식을 가져옵니다.PropertyType gets the type of the property.
CanResetValue 구성 요소를 다시 설정 하면 요소의 값이 변경 되는지 여부를 나타냅니다.CanResetValue indicates whether resetting the component changes the value of the component.
GetValue 구성 요소에서 속성의 현재 값을 반환 합니다.GetValue returns the current value of the property on a component.
ResetValue 구성 요소의이 속성의 값을 다시 설정합니다.ResetValue resets the value for this property of the component.
SetValue 요소의 값을 다른 값으로 설정합니다.SetValue sets the value of the component to a different value.
ShouldSerializeValue 이 속성의 값을 유지 해야 하는지 여부를 나타냅니다.ShouldSerializeValue indicates whether the value of this property needs to be persisted.
일반적으로 abstract
멤버 리플렉션을 통해 구현 됩니다.Typically, the abstract
members are implemented through reflection. 리플렉션에 대 한 자세한 내용은의 항목을 참조 하세요 리플렉션합니다.For more information about reflection, see the topics in Reflection.
생성자
PropertyDescriptor(MemberDescriptor) |
지정된 PropertyDescriptor의 이름과 특성을 사용하여 MemberDescriptor 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the PropertyDescriptor class with the name and attributes in the specified MemberDescriptor. |
PropertyDescriptor(MemberDescriptor, Attribute[]) |
지정된 PropertyDescriptor의 이름과 MemberDescriptor 및 MemberDescriptor 배열 모두의 특성을 사용하여 Attribute 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the PropertyDescriptor class with the name in the specified MemberDescriptor and the attributes in both the MemberDescriptor and the Attribute array. |
PropertyDescriptor(String, Attribute[]) |
지정된 이름과 특성을 사용하여 PropertyDescriptor 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the PropertyDescriptor class with the specified name and attributes. |
속성
AttributeArray |
특성 배열을 가져오거나 설정합니다.Gets or sets an array of attributes. (다음에서 상속됨 MemberDescriptor) |
Attributes |
이 멤버에 대한 특성 컬렉션을 가져옵니다.Gets the collection of attributes for this member. (다음에서 상속됨 MemberDescriptor) |
Category |
CategoryAttribute에 지정된, 해당 멤버가 속해 있는 범주의 이름을 가져옵니다.Gets the name of the category to which the member belongs, as specified in the CategoryAttribute. (다음에서 상속됨 MemberDescriptor) |
ComponentType |
파생 클래스에서 재정의된 경우 이 속성이 바인딩된 구성 요소의 형식을 가져옵니다.When overridden in a derived class, gets the type of the component this property is bound to. |
Converter |
이 속성의 형식 변환기를 가져옵니다.Gets the type converter for this property. |
Description |
DescriptionAttribute에 지정된 멤버 설명을 가져옵니다.Gets the description of the member, as specified in the DescriptionAttribute. (다음에서 상속됨 MemberDescriptor) |
DesignTimeOnly |
DesignOnlyAttribute에 지정된, 이 멤버가 디자인 타임에만 설정되어야 하는지 여부를 가져옵니다.Gets whether this member should be set only at design time, as specified in the DesignOnlyAttribute. (다음에서 상속됨 MemberDescriptor) |
DisplayName |
속성 창 등의 창에 표시될 수 있는 이름을 가져옵니다.Gets the name that can be displayed in a window, such as a Properties window. (다음에서 상속됨 MemberDescriptor) |
IsBrowsable |
BrowsableAttribute에 지정된, 해당 멤버를 찾아볼 수 있는지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether the member is browsable, as specified in the BrowsableAttribute. (다음에서 상속됨 MemberDescriptor) |
IsLocalizable |
LocalizableAttribute에 지정된, 이 속성이 지역화되어야 하는지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether this property should be localized, as specified in the LocalizableAttribute. |
IsReadOnly |
파생 클래스에서 재정의된 경우 이 속성이 읽기 전용인지 여부를 나타내는 값을 가져옵니다.When overridden in a derived class, gets a value indicating whether this property is read-only. |
Name |
해당 멤버의 이름을 가져옵니다.Gets the name of the member. (다음에서 상속됨 MemberDescriptor) |
NameHashCode |
GetHashCode()에 지정된, 멤버 이름의 해시 코드를 가져옵니다.Gets the hash code for the name of the member, as specified in GetHashCode(). (다음에서 상속됨 MemberDescriptor) |
PropertyType |
파생 클래스에서 재정의된 경우 속성 형식을 가져옵니다.When overridden in a derived class, gets the type of the property. |
SerializationVisibility |
DesignerSerializationVisibilityAttribute에 지정된, 이 속성이 serialize되어야 하는지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether this property should be serialized, as specified in the DesignerSerializationVisibilityAttribute. |
SupportsChangeEvents |
이 속성의 값 변경 알림이 속성 설명자 외부에서 발생되었는지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether value change notifications for this property may originate from outside the property descriptor. |
메서드
AddValueChanged(Object, EventHandler) |
이 속성이 변경되면 다른 개체에서 알림을 받을 수 있도록 합니다.Enables other objects to be notified when this property changes. |
CanResetValue(Object) |
파생 클래스에서 재정의된 경우 개체를 다시 설정하면 해당 값이 변경되는지 여부를 반환합니다.When overridden in a derived class, returns whether resetting an object changes its value. |
CreateAttributeCollection() |
생성자에 전달된 특성 배열을 사용하여 특성 컬렉션을 만듭니다.Creates a collection of attributes using the array of attributes passed to the constructor. (다음에서 상속됨 MemberDescriptor) |
CreateInstance(Type) |
지정된 형식의 인스턴스를 만듭니다.Creates an instance of the specified type. |
Equals(Object) |
이 개체를 다른 개체와 비교하여 두 개체가 같은지 확인합니다.Compares this to another object to see if they are equivalent. |
FillAttributes(IList) |
PropertyDescriptor의 특성을 부모 클래스의 지정된 특성 목록에 추가합니다.Adds the attributes of the PropertyDescriptor to the specified list of attributes in the parent class. |
GetChildProperties() |
기본 PropertyDescriptorCollection을 반환합니다.Returns the default PropertyDescriptorCollection. |
GetChildProperties(Attribute[]) |
지정된 특성 배열을 필터로 사용하여 PropertyDescriptorCollection을 반환합니다.Returns a PropertyDescriptorCollection using a specified array of attributes as a filter. |
GetChildProperties(Object) |
지정된 개체에 대해 PropertyDescriptorCollection을 반환합니다.Returns a PropertyDescriptorCollection for a given object. |
GetChildProperties(Object, Attribute[]) |
지정된 특성 배열을 필터로 사용하여 지정된 개체에 대한 PropertyDescriptorCollection을 반환합니다.Returns a PropertyDescriptorCollection for a given object using a specified array of attributes as a filter. |
GetEditor(Type) |
지정된 형식의 편집기를 가져옵니다.Gets an editor of the specified type. |
GetHashCode() |
해당 개체의 해시 코드를 반환합니다.Returns the hash code for this object. |
GetInvocationTarget(Type, Object) |
이 메서드는 멤버를 호출하는 동안 사용해야 하는 개체를 반환합니다.This method returns the object that should be used during invocation of members. |
GetType() |
현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance. (다음에서 상속됨 Object) |
GetTypeFromName(String) |
해당 이름을 사용하는 형식을 반환합니다.Returns a type using its name. |
GetValue(Object) |
파생 클래스에서 재정의된 경우 구성 요소에 대한 현재 속성 값을 가져옵니다.When overridden in a derived class, gets the current value of the property on a component. |
GetValueChangedHandler(Object) |
특정 구성 요소에 대한 |
MemberwiseClone() |
현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object. (다음에서 상속됨 Object) |
OnValueChanged(Object, EventArgs) |
구현된 |
RemoveValueChanged(Object, EventHandler) |
이 속성이 변경되면 다른 개체에서 알림을 받을 수 있도록 합니다.Enables other objects to be notified when this property changes. |
ResetValue(Object) |
파생 클래스에서 재정의된 경우 구성 요소의 이 속성 값을 기본값으로 다시 설정합니다.When overridden in a derived class, resets the value for this property of the component to the default value. |
SetValue(Object, Object) |
파생 클래스에서 재정의된 경우 구성 요소의 값을 다른 값으로 설정합니다.When overridden in a derived class, sets the value of the component to a different value. |
ShouldSerializeValue(Object) |
파생 클래스에서 재정의된 경우 이 속성 값이 지속되어야 하는지 여부를 나타내는 값을 확인합니다.When overridden in a derived class, determines a value indicating whether the value of this property needs to be persisted. |
ToString() |
현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object. (다음에서 상속됨 Object) |