We differentiate ASP. NET attributes into simple attributes and complex attributes based on different manifestations of ASP. NET attributes.
The following describes the ASP. NET attribute representation.
Simple attributes are shown in the following format. Everyone is familiar with attributes that contain sub-attributes, called complex objects, such as Font attributes.
(1) representation of a hyphen
(2) Representation of inner set attributes, such as defining styles
(3) Representation of inner set attributes, such as DropDownList
Basic usage of complex attributes
See how I did it. I see some metadata below. If you are not familiar with it, please refer to MSDN.
The following code records the custom information.
1. Define Enumeration
- UsingSystem;
-
- NamespaceCustomComponents
- {
- /**////<Summary>
- /// Occupation
- ///</Summary>
- PublicenumMetier
- {
- Teachers, programmers, and writers
- }
- }
2. Define complex attributes
- UsingSystem;
- UsingSystem. ComponentModel;
-
- NamespaceCustomComponents
- {
-
-
- /**////<Summary>
- /// Address set
- ///</Summary>
- PublicclassAddress
- {
- PrivateStringstreet=Null;
- PrivateStringcity=Null;
- PrivateStringstate=Null;
- PrivateStringzip=Null;
-
- PublicStringStreet
- {
- Get
- {
- Returnstreet;
- }
- Set
- {
- Street=Value;
- }
- }
-
-
- PublicStringCity
- {
- Get
- {
- Returncity;
- }
- Set
- {
- City=Value;
- }
- }
-
- PublicStringState
- {
- Get
- {
- Returnstate;
- }
- Set
- {
- State=Value;
- }
- }
-
- PublicStringZip
- {
- Get
- {
- Returnzip;
- }
- Set
- {
- Zip=Value;
- }
- }
- }
- }
3. Render Control
4. Define controls on the ASP. NET page
Open the background code, enter the following code to check the attributes and find that the attributes exist. For example, open the view and find that the control can display the attributes. The only difference is that the attribute cannot be recognized as a valid attribute, these attributes cannot be found in the source view.
5. solution 4: Failure to display valid attributes (in fact, the above tests have implemented complex attributes ).
Solution: Add a metadata to CustomAddress in the Custom class, as shown below:
- [Description ("address set")]
- [DesignerSerializationVisibility (DesignerSerializationVisibility. Content)]
- PublicAddressCustomAddress
- {
- Get
- {
- Returnaddress;
- }
- }
6. Implement maddress attribute folding
Solution: Add a metadata to the Address class, as shown below:
- [TypeConverter(typeof(ExpandableObjectConverter))]
- publicclassAddress
- {.}
The above describes the ASP. NET attribute Representation
- Microsoft released multiple function updates for ASP. net mvc 2 preview Edition
- ASP. NET Server custom control security guidelines
- Analysis of ASP. NET programming standards and Their encoding specifications
- Introduction to ASP. NET sessions
- ASP. NET programming tool ASP. NET Web Matrix