Complex attributes and status management
Complex attribute statement / persistence:
The so-called complex attributes, that is, the attributes that are typically not available to the basic data type of the CLR. For example, FontInfo, representing a font attribute, including Bold, Name, Size, Color and other information (commonly referred to as sub-attributes).
For complex properties, the control is declared, usually using the attribute-sub-property hyphen represents a sub-property of the complex attribute.
The scribe part represents a Font property.
Another expression of complex attributes is that the complex attributes are nestled in the control declaration tag, and the internal properties persistence is ridicpeted. Such as:
ask: DataGrid>
Complex attribute sequence / persistent design
Implementation is implemented outside the control, using metadata (Attribute). For sub-properties implemented by hyphens, you can affect the designer to implement design support by setting a specific Attribute.
DesignerSerializationVisibility actually refers to the property class of DesignerSerializationVisibilityAttribute in ASP.NET, specified in metadata and set to:
DesignerSerializationVisibility.Content can let the designer know that the content of the complex attribute should be sequenced instead of the attribute itself
DesignerSerializationVisibility.hidden lets the designer ignore the properties and properties
DesignerserializationVisibility.visible allows the designer to serialize in normal way
The so-called normal way is to be characterized by character, and if it does not belong to these, the byte manage persistence property (of course, for complex attributes).
NotifyParentProperty (TRUE) Indicates that the properties browser changes the modification of the complicated attribute to the control, and it is notified that the individual objects (usually give the designer application), inform the property already "dirty". These agreements are important to control designers and designer developers and ASP.NET pages.
For the properties of the label nested mode, Parsechilren (TRUE) should be used to specify the lasting properties, and the designer implementation of the nested method should specify the PersistChildren (false) to let the designer convert the nested label into a complex attribute (rather than Embedded sub-control)
Type converter
In order to interpret the persistent form of complex attributes to design runtime, you need to specify a type converter for complex attributes. The basic goal is to interpret the persistent form to the type of CLR support, and also express the CLR type of the attribute to design, run Persistent form. The font-size = "8pt" is converted to an int 32, and the 8 persistence of complex attributes is font-size = "8pt".
The implementation of the type converter does not depend on any user interface function. Therefore, the same type of converter can be applied in a Windows Form and a web form.
Type converters inherit from System.comPonentModel.TypeConverter.
To implement the type converter:
1. Define a class that is derived from System.comPonentModel.TypeConverter.
2, rewrite the CANCONVERTFROM method, specify the type of converter to be converted from the transition. This method is the overload method. 3, rewrite the ConvertFrom method for implementing the conversion. This method is the overload method.
4. Rewote the CANCONVERTTO method, specify the type of converter to convert. Converting to string type does not need to override this method. This method is the overload method.
5, rewrite the ConvertTo method of implementing the conversion. This method is the overload method.
6, rewrite the IsValid method to perform verification. This method is the overload method.
Determines a particular type converter through TypeConverter (Type (SomeCustimoziedTypeConverter).
For ASP.NET applications, how to keep the complex attributes of the controls between the two pages are important. The default status management of the Control class is handed over to the ViewSatte dictionary, and complex properties are not possible when using ViewState, which must be used to participate in status management.
Interface istateManager
{
Public Bool IsTrackingViewState; // When implemented by a class, you get a value, indicating whether the server control is tracking its view status changes.
Void LoadViewState (Object State); // When implemented by a class, the control view status of the previously saved server control is loaded.
Object SaveViewState (); // Saves the view status changes of the server control to Object when implemented.
Void trackViewState (); // When implemented by a class, the server control tracks its view status changes.
}
Control's ViewSatte attribute is actually a complex attribute, essentially a dictionary class, by implementing the ISTATEMANAGER interface to participate in status management (details of ViewState):
1. The data type of ViewState is the complex attribute System.Web.ui.StateBag class. Implement the dictionary of the ISTATEMANAGER interface. Save multiple key / value pairs, keys are strings, values object, when an object is automatically added to state, automatically add a stateItem object, there is actual attribute value and related Boolean flag , Knowledge this attribute (state) has been modified after initialization.
2, the value of this function can correspond to the internal Boolean variable of StateBag in the interface of the interface.
3, SaveViewsate, enumerate the project, create and return two ArrayList, respectively, the modified keys and values.
4, LoadViewSatet performs SaveState's inverse operation.
When the properties are saved in ViewSatte, their status is automatically maintained. You can save any number of controls when you need to reduce the cut-by-transfer transfer in ViewState (instead of all data, from efficiency to eliminate redundant data), and any saved data must be serialized by Losformatter when the data saved in ViewState red must be
The status saving of all complex properties should be implemented
IStateManager
To convert complex attributes to can
ViewState
Simple properties stored in, and
ViewState
Simple property recovery combination in medium saved is complex attributes.