2016-11-24 (C # Custom feature) (not finished)

Source: Internet
Author: User

--------------------------------------------Custom Features---------------------------------------------------

The above phrase is saying that you can create a keyword to define our own rules?

The custom features in C # are placed on the above [custom attribute name (,)] to indicate that XXX uses this custom feature.

There is also a prefix that explains what kind of data the custom feature uses such as the class return value structure. Wait, wait, he'll judge himself. Usage [method: Custom characteristics (,)]

An attribute is just an instance of a type and all attributes inherit from System.Attribute

The constructor parameter of an attribute is that the positional parameter is required to be worn in the setting field or the parameter of the property is called named parameter is optional

For example [DllImport ("Ternel32", Charset=charset.auto,setlasterror=true)]

Define your own features

Open a namespace so that its attributes inherit from attribute and then the class name suffix is attribute public constructor access modifier more than one display constructor

If our custom feature points to the application on the enumeration, then add the custom attribute to the enumeration above.

Attributeusage[attributetarget.enum,inherited=false];

You can tell the compiler what type is applied to the type we define.

1> no specified type applies to all elements 2> applies to a target only once 3> can be inherited

2016-11-24 (C # Custom feature) (not finished)

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.