|
Este artículo se tradujo de forma manual. Mueva el puntero sobre las frases del artículo para ver el texto original.
|
Traducción
Original
|
PropertyDescriptor (Clase)
System.ComponentModel.MemberDescriptor
System.ComponentModel.PropertyDescriptor
System.ComponentModel.DependencyPropertyDescriptor
System.ComponentModel.TypeConverter.SimplePropertyDescriptor
Ensamblado: System (en System.dll)
El tipo PropertyDescriptor expone los siguientes miembros.
| Nombre | Descripción | |
|---|---|---|
![]() ![]() | PropertyDescriptor(MemberDescriptor) | |
![]() ![]() | PropertyDescriptor(MemberDescriptor, Attribute[]) | |
![]() ![]() | PropertyDescriptor(String, Attribute[]) |
| Nombre | Descripción | |
|---|---|---|
![]() ![]() | AttributeArray | |
![]() | Attributes | |
![]() | Category | |
![]() ![]() | ComponentType | |
![]() | Converter | |
![]() | Description | |
![]() | DesignTimeOnly | |
![]() ![]() | DisplayName | |
![]() | IsBrowsable | |
![]() | IsLocalizable | |
![]() ![]() | IsReadOnly | |
![]() ![]() | Name | |
![]() ![]() | NameHashCode | |
![]() ![]() | PropertyType | |
![]() | SerializationVisibility | |
![]() ![]() | SupportsChangeEvents |
| Nombre | Descripción | |
|---|---|---|
![]() ![]() | AddValueChanged | |
![]() ![]() | CanResetValue | |
![]() ![]() | CreateAttributeCollection | |
![]() | CreateInstance | |
![]() ![]() | Equals | En XNA Framework 3.0, este miembro se hereda de Object.Equals(Object). |
![]() ![]() | FillAttributes | En XNA Framework 3.0, este miembro se hereda de MemberDescriptor.FillAttributes(IList). |
![]() ![]() | Finalize | |
![]() | GetChildProperties() | |
![]() | GetChildProperties(Attribute[]) | |
![]() | GetChildProperties(Object) | |
![]() | GetChildProperties(Object, Attribute[]) | |
![]() | GetEditor | |
![]() ![]() | GetHashCode | En XNA Framework, este miembro está invalidado por GetHashCode(). |
![]() | GetInvocationTarget | |
![]() ![]() | GetType | |
![]() | GetTypeFromName | |
![]() ![]() | GetValue | |
![]() ![]() | GetValueChangedHandler | |
![]() ![]() | MemberwiseClone | |
![]() ![]() | OnValueChanged | |
![]() ![]() | RemoveValueChanged | |
![]() ![]() | ResetValue | |
![]() ![]() | SetValue | |
![]() ![]() | ShouldSerializeValue | |
![]() ![]() | ToString |
Converter contiene el TypeConverter de esta propiedad. IsLocalizable indica si se debe traducir esta propiedad. GetEditor devuelve un editor del tipo especificado.
ComponentType contiene el tipo de componente al que está enlazada esta propiedad. IsReadOnly indica si esta propiedad es de sólo lectura. PropertyType obtiene el tipo de propiedad. CanResetValue indica si al restablecer el componente cambia su valor. GetValue devuelve el valor actual de la propiedad en un componente. ResetValue restablece el valor de esta propiedad del componente. SetValue establece el valor del componente en otro valor. ShouldSerializeValue indica si se debe almacenar el valor de esta propiedad.
Nota |
|---|
El atributo HostProtectionAttribute aplicado a este tipo o miembro tiene el siguiente valor de la propiedad Resources: SharedState. El atributo HostProtectionAttribute no afecta a las aplicaciones de escritorio (que normalmente se inician haciendo doble clic en un icono, escribiendo un comando o introduciendo una dirección URL en el explorador). Para obtener más información, vea la clase HostProtectionAttribute o Programación en SQL Server y atributos de protección de host. |
// 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';
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("existing"); } if (newAttrs == null) { 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; } } }
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); } } } ... 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() { } } }
Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2
.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
