Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the expression of the ASP.NET attribute

Shulou Source: shulou.com Published: 2022-06-02 22:03:27 09月25日 Update

Today, I will talk to you about the form of expression of ASP.NET attributes, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

According to the different forms of expression of ASP.NET attributes, we divide them into simple attributes and complex attributes.

Let's take a look at the representation of ASP.NET attributes.

Simple attributes are represented as follows. We are all familiar with attributes that contain sub-attributes, which are called complex objects, such as Font attributes.

(1) the expression of hyphens

(2) the representation of inlaid attributes, such as defining styles.

(3) the representation of embedded collection properties, such as DropDownList

Basic usage of complex attributes

Please see how I do it, about the following to see some metadata, if you are not familiar with, please refer to MSDN.

The following code records a custom message.

1. Define enumeration

UsingSystem; namespaceCustomComponents {/ * * / Professional / publicenumMetier {teacher, programmer, writer}}

two。 Define complex attributes

UsingSystem; usingSystem.ComponentModel; namespaceCustomComponents {/ * * / address Collection / 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 properties, and find that the properties exist, such as the following figure, and then open the view, and find that the control can display the properties, but cannot recognize the properties as valid properties and cannot find them in the source view.

5. Solve the problem that 4 cannot display valid properties, (in fact, the above tests have already implemented complex properties).

Solution: add a metadata to the CustomAddress in the Custom class, as follows

[Description ("address set")] [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)] publicAddressCustomAddress {get {returnaddress;}}

6. Achieve CustomAddress attribute folding effect

Solution: add a metadata to the Address class, as follows

[TypeConverter (typeof (ExpandableObjectConverter))] publicclassAddress {.} after reading the above, do you have any further understanding of the representation of the ASP.NET attribute? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Property form complexity code content control data method valid address view different writer usage information background object that is effect teacher Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS Shulou Information Microsoft MariaDB