|
Tento článek byl přeložen strojově počítačem. Původní text zobrazíte přesunutím ukazatele myši nad jednotlivé věty článku. Další informace
|
Překlad
Originál
|
PropertyDescriptor – třída
System.ComponentModel.MemberDescriptor
System.ComponentModel.PropertyDescriptor
System.ComponentModel.DependencyPropertyDescriptor
System.ComponentModel.TypeConverter.SimplePropertyDescriptor
Sestavení: System (v System.dll)
Typ PropertyDescriptor zveřejňuje následující členy.
| Název | Popis | |
|---|---|---|
![]() ![]() | PropertyDescriptor(MemberDescriptor) | |
![]() ![]() | PropertyDescriptor(MemberDescriptor, Attribute[]) | |
![]() ![]() | PropertyDescriptor(String, Attribute[]) |
| Název | Popis | |
|---|---|---|
![]() ![]() | AttributeArray | |
![]() | Attributes | |
![]() | Category | |
![]() ![]() | ComponentType | |
![]() | Converter | |
![]() | Description | |
![]() | DesignTimeOnly | |
![]() ![]() | DisplayName | |
![]() | IsBrowsable | |
![]() | IsLocalizable | |
![]() ![]() | IsReadOnly | |
![]() ![]() | Name | |
![]() ![]() | NameHashCode | |
![]() ![]() | PropertyType | |
![]() | SerializationVisibility | |
![]() ![]() | SupportsChangeEvents |
| Název | Popis | |
|---|---|---|
![]() ![]() | AddValueChanged | |
![]() ![]() | CanResetValue | |
![]() ![]() | CreateAttributeCollection | |
![]() | CreateInstance | |
![]() ![]() | Equals | V XNA Framework 3.0 je tento člen zděděn od Object.Equals(Object). |
![]() ![]() | FillAttributes | V XNA Framework 3.0 je tento člen zděděn od MemberDescriptor.FillAttributes(IList). |
![]() ![]() | Finalize | Umožňuje objektu pokusit se uvolnit prostředky a provést další operace vyčištění předtím, než je odstraněn při uvolňování paměti. |
![]() | GetChildProperties() | |
![]() | GetChildProperties(Attribute[]) | |
![]() | GetChildProperties(Object) | |
![]() | GetChildProperties(Object, Attribute[]) | |
![]() | GetEditor | |
![]() ![]() | GetHashCode | V XNA Framework je tento člen přepsán GetHashCode(). |
![]() | GetInvocationTarget | |
![]() ![]() | GetType | |
![]() | GetTypeFromName | |
![]() ![]() | GetValue | |
![]() ![]() | GetValueChangedHandler | |
![]() ![]() | MemberwiseClone | |
![]() ![]() | OnValueChanged | |
![]() ![]() | RemoveValueChanged | |
![]() ![]() | ResetValue | |
![]() ![]() | SetValue | |
![]() ![]() | ShouldSerializeValue | |
![]() ![]() | ToString |
Converter obsahuje TypeConverter pro vlastnost. IsLocalizable označuje, zda by tato vlastnost lokalizovat. GetEditor Vrací editoru zadaného typu.
ComponentType obsahuje typ součást, kterou je povinen tuto vlastnost. IsReadOnly označuje, zda je tato vlastnost jen pro čtení. PropertyType získá typ vlastnosti. CanResetValue označuje, zda komponenta resetování změní hodnotu komponenty. GetValue Vrací aktuální hodnotu vlastnosti komponenty. ResetValue Nastaví hodnotu pro tuto vlastnost komponenty. SetValue Nastaví hodnotu komponenty na jinou hodnotu. ShouldSerializeValue označuje, zda hodnota této vlastnosti je trvalé.
Poznámka |
|---|
Atribut HostProtectionAttribute použitý na tento typ nebo člen má následující hodnotu vlastnosti Resources: SharedState. Atribut HostProtectionAttribute nemá vliv na běžné aplikace (které jsou obvykle spouštěny dvojitým kliknutím na ikonu, zadáním příkazu nebo zadáním adresy URL v prohlížeči). Další informace naleznete v třídě HostProtectionAttribute nebo v tématu SQL Server Programming and Host Protection Attributes. |
// 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 nebo novější, Windows XP SP3, 64bitová verze systému Windows XP SP2, Windows Server 2008 (není podpora v roli Server Core), Windows Server 2008 R2 (podpora v roli Server Core s aktualizací SP1 nebo novější), Windows Server 2003 SP2
.NET Framework nepodporuje některé verze platforem. Seznam podporovaných verzí naleznete v tématu Požadavky na systém rozhraní .NET framework.
