Overview ASP. NET attribute representations

Source: Internet
Author: User

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

 
 
  1. UsingSystem;
  2.  
  3. NamespaceCustomComponents
  4. {
  5. /**////<Summary> 
  6. /// Occupation
  7. ///</Summary> 
  8. PublicenumMetier
  9. {
  10. Teachers, programmers, and writers
  11. }
  12. }

2. Define complex attributes

 
 
  1. UsingSystem;
  2. UsingSystem. ComponentModel;
  3.  
  4. NamespaceCustomComponents
  5. {
  6.  
  7.  
  8. /**////<Summary> 
  9. /// Address set
  10. ///</Summary> 
  11. PublicclassAddress
  12. {
  13. PrivateStringstreet=Null;
  14. PrivateStringcity=Null;
  15. PrivateStringstate=Null;
  16. PrivateStringzip=Null;
  17.  
  18. PublicStringStreet
  19. {
  20. Get
  21. {
  22. Returnstreet;
  23. }
  24. Set
  25. {
  26. Street=Value;
  27. }
  28. }
  29.  
  30.  
  31. PublicStringCity
  32. {
  33. Get
  34. {
  35. Returncity;
  36. }
  37. Set
  38. {
  39. City=Value;
  40. }
  41. }
  42.  
  43. PublicStringState
  44. {
  45. Get
  46. {
  47. Returnstate;
  48. }
  49. Set
  50. {
  51. State=Value;
  52. }
  53. }
  54.  
  55. PublicStringZip
  56. {
  57. Get
  58. {
  59. Returnzip;
  60. }
  61. Set
  62. {
  63. Zip=Value;
  64. }
  65. }
  66. }
  67. }

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:

 
 
  1. [Description ("address set")]
  2. [DesignerSerializationVisibility (DesignerSerializationVisibility. Content)]
  3. PublicAddressCustomAddress
  4. {
  5. Get
  6. {
  7. Returnaddress;
  8. }
  9. }

6. Implement maddress attribute folding

Solution: Add a metadata to the Address class, as shown below:

 
 
  1. [TypeConverter(typeof(ExpandableObjectConverter))]  
  2. publicclassAddress  
  3. {.} 

The above describes the ASP. NET attribute Representation

  1. Microsoft released multiple function updates for ASP. net mvc 2 preview Edition
  2. ASP. NET Server custom control security guidelines
  3. Analysis of ASP. NET programming standards and Their encoding specifications
  4. Introduction to ASP. NET sessions
  5. ASP. NET programming tool ASP. NET Web Matrix

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.