C# Класс System.ComponentModel.ReflectPropertyDescriptor

ReflectPropertyDescriptor defines a property. Properties are the main way that a user can set up the state of a component. The ReflectPropertyDescriptor class takes a component class that the property lives on, a property name, the type of the property, and various attributes for the property. For a property named XXX of type YYY, the associated component class is required to implement two methods of the following form:

public YYY GetXXX(); public void SetXXX(YYY value); The component class can optionally implement two additional methods of the following form: public boolean ShouldSerializeXXX(); public void ResetXXX(); These methods deal with a property's default value. The ShouldSerializeXXX() method returns true if the current value of the XXX property is different than it's default value, so that it should be persisted out. The ResetXXX() method resets the XXX property to its default value. If the ReflectPropertyDescriptor includes the default value of the property (using the DefaultValueAttribute), the ShouldSerializeXXX() and ResetXXX() methods are ignored. If the ReflectPropertyDescriptor includes a reference to an editor then that value editor will be used to edit the property. Otherwise, a system-provided editor will be used. Various attributes can be passed to the ReflectPropertyDescriptor, as are described in Attribute. ReflectPropertyDescriptors can be obtained by a user programmatically through the ComponentManager.
Наследование: PropertyDescriptor
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
ExtenderCanResetValue bool
ExtenderGetReceiverType Type
ExtenderGetType Type
ExtenderGetValue object
ExtenderResetValue void
ExtenderSetValue void
ExtenderShouldSerializeValue bool
OnINotifyPropertyChanged void

Открытые методы

Метод Описание
AddValueChanged ( object component, EventHandler handler ) : void

Allows interested objects to be notified when this property changes.

CanResetValue ( object component ) : bool

Indicates whether reset will change the value of the component. If there is a DefaultValueAttribute, then this will return true if getValue returns something different than the default value. If there is a reset method and a ShouldSerialize method, this will return what ShouldSerialize returns. If there is just a reset method, this always returns true. If none of these cases apply, this returns false.

GetValue ( object component ) : object

Retrieves the current value of the property on component, invoking the getXXX method. An exception in the getXXX method will pass through.

ReflectPropertyDescriptor ( Type componentClass, PropertyDescriptor oldReflectPropertyDescriptor, Attribute attributes ) : System.Collections

This constructor takes an existing ReflectPropertyDescriptor and modifies it by merging in the passed-in attributes.

ReflectPropertyDescriptor ( Type componentClass, string name, Type type, Attribute attributes ) : System.Collections

The main constructor for ReflectPropertyDescriptors.

ReflectPropertyDescriptor ( Type componentClass, string name, Type type, PropertyInfo propInfo, MethodInfo getMethod, MethodInfo setMethod, Attribute attrs ) : System.Collections

A constructor for ReflectPropertyDescriptors that have no attributes.

ReflectPropertyDescriptor ( Type componentClass, string name, Type type, Type receiverType, MethodInfo getMethod, MethodInfo setMethod, Attribute attrs ) : System.Collections

A constructor for ReflectPropertyDescriptors that creates an extender property.

RemoveValueChanged ( object component, EventHandler handler ) : void

Allows interested objects to be notified when this property changes.

ResetValue ( object component ) : void

Will reset the default value for this property on the component. If there was a default value passed in as a DefaultValueAttribute, that value will be set as the value of the property on the component. If there was no default value passed in, a ResetXXX method will be looked for. If one is found, it will be invoked. If one is not found, this is a nop.

SetValue ( object component, object value ) : void

This will set value to be the new value of this property on the component by invoking the setXXX method on the component. If the value specified is invalid, the component should throw an exception which will be passed up. The component designer should design the property so that getXXX following a setXXX should return the value passed in if no exception was thrown in the setXXX call.

ShouldSerializeValue ( object component ) : bool

Indicates whether the value of this property needs to be persisted. In other words, it indicates whether the state of the property is distinct from when the component is first instantiated. If there is a default value specified in this ReflectPropertyDescriptor, it will be compared against the property's current value to determine this. If there is't, the ShouldSerializeXXX method is looked for and invoked if found. If both these routes fail, true will be returned. If this returns false, a tool should not persist this property's value.

Защищенные методы

Метод Описание
FillAttributes ( IList attributes ) : void
OnValueChanged ( object component, EventArgs e ) : void

This should be called by your property descriptor implementation when the property value has changed.

Приватные методы

Метод Описание
ExtenderCanResetValue ( IExtenderProvider provider, object component ) : bool
ExtenderGetReceiverType ( ) : Type
ExtenderGetType ( IExtenderProvider provider ) : Type
ExtenderGetValue ( IExtenderProvider provider, object component ) : object
ExtenderResetValue ( IExtenderProvider provider, object component, PropertyDescriptor notifyDesc ) : void
ExtenderSetValue ( IExtenderProvider provider, object component, object value, PropertyDescriptor notifyDesc ) : void
ExtenderShouldSerializeValue ( IExtenderProvider provider, object component ) : bool
OnINotifyPropertyChanged ( object component, PropertyChangedEventArgs e ) : void

Handles INotifyPropertyChanged.PropertyChange events from components. If event pertains to this property, issue a ValueChanged event.

Описание методов

AddValueChanged() публичный Метод

Allows interested objects to be notified when this property changes.
public AddValueChanged ( object component, EventHandler handler ) : void
component object
handler EventHandler
Результат void

CanResetValue() публичный Метод

Indicates whether reset will change the value of the component. If there is a DefaultValueAttribute, then this will return true if getValue returns something different than the default value. If there is a reset method and a ShouldSerialize method, this will return what ShouldSerialize returns. If there is just a reset method, this always returns true. If none of these cases apply, this returns false.
public CanResetValue ( object component ) : bool
component object
Результат bool

FillAttributes() защищенный Метод

protected FillAttributes ( IList attributes ) : void
attributes IList
Результат void

GetValue() публичный Метод

Retrieves the current value of the property on component, invoking the getXXX method. An exception in the getXXX method will pass through.
public GetValue ( object component ) : object
component object
Результат object

OnValueChanged() защищенный Метод

This should be called by your property descriptor implementation when the property value has changed.
protected OnValueChanged ( object component, EventArgs e ) : void
component object
e EventArgs
Результат void

ReflectPropertyDescriptor() публичный Метод

This constructor takes an existing ReflectPropertyDescriptor and modifies it by merging in the passed-in attributes.
public ReflectPropertyDescriptor ( Type componentClass, PropertyDescriptor oldReflectPropertyDescriptor, Attribute attributes ) : System.Collections
componentClass Type
oldReflectPropertyDescriptor PropertyDescriptor
attributes Attribute
Результат System.Collections

ReflectPropertyDescriptor() публичный Метод

The main constructor for ReflectPropertyDescriptors.
public ReflectPropertyDescriptor ( Type componentClass, string name, Type type, Attribute attributes ) : System.Collections
componentClass Type
name string
type Type
attributes Attribute
Результат System.Collections

ReflectPropertyDescriptor() публичный Метод

A constructor for ReflectPropertyDescriptors that have no attributes.
public ReflectPropertyDescriptor ( Type componentClass, string name, Type type, PropertyInfo propInfo, MethodInfo getMethod, MethodInfo setMethod, Attribute attrs ) : System.Collections
componentClass Type
name string
type Type
propInfo System.Reflection.PropertyInfo
getMethod System.Reflection.MethodInfo
setMethod System.Reflection.MethodInfo
attrs Attribute
Результат System.Collections

ReflectPropertyDescriptor() публичный Метод

A constructor for ReflectPropertyDescriptors that creates an extender property.
public ReflectPropertyDescriptor ( Type componentClass, string name, Type type, Type receiverType, MethodInfo getMethod, MethodInfo setMethod, Attribute attrs ) : System.Collections
componentClass Type
name string
type Type
receiverType Type
getMethod System.Reflection.MethodInfo
setMethod System.Reflection.MethodInfo
attrs Attribute
Результат System.Collections

RemoveValueChanged() публичный Метод

Allows interested objects to be notified when this property changes.
public RemoveValueChanged ( object component, EventHandler handler ) : void
component object
handler EventHandler
Результат void

ResetValue() публичный Метод

Will reset the default value for this property on the component. If there was a default value passed in as a DefaultValueAttribute, that value will be set as the value of the property on the component. If there was no default value passed in, a ResetXXX method will be looked for. If one is found, it will be invoked. If one is not found, this is a nop.
public ResetValue ( object component ) : void
component object
Результат void

SetValue() публичный Метод

This will set value to be the new value of this property on the component by invoking the setXXX method on the component. If the value specified is invalid, the component should throw an exception which will be passed up. The component designer should design the property so that getXXX following a setXXX should return the value passed in if no exception was thrown in the setXXX call.
public SetValue ( object component, object value ) : void
component object
value object
Результат void

ShouldSerializeValue() публичный Метод

Indicates whether the value of this property needs to be persisted. In other words, it indicates whether the state of the property is distinct from when the component is first instantiated. If there is a default value specified in this ReflectPropertyDescriptor, it will be compared against the property's current value to determine this. If there is't, the ShouldSerializeXXX method is looked for and invoked if found. If both these routes fail, true will be returned. If this returns false, a tool should not persist this property's value.
public ShouldSerializeValue ( object component ) : bool
component object
Результат bool