Unity game development-C # feature Attribute and automation,

Source: Internet
Author: User

Unity game development-C # feature Attribute and automation,

This article mainly describes how to use Attribute in C # and its possible application scenarios.

For example, you write the player's blood volume, attack, defense, and other attributes into the enumeration. Then the interface may have many places to obtain the attribute description text based on this enumeration.

For example, when you create a network framework, a Protocol number corresponds to a class or a method.

For example, if you do an ORM, whether the attributes of a class are mapped to the attributes in the persistence file, and what are the attributes mapped to the past.


1. What is Attribute? If you have used Java Annotation, You can regard Attribute as Annotation. If you are not familiar with Attribute, you don't have to worry about it. Let's take a look at the official explanation:

Attribute Class associates predefined system information or user-defined custom information with the target element. "Xml: space =" preserve "> The Attribute class associates predefined system information or user-defined custom information with a target element. A target element can be an assembly, class, constructor, delegate, enum, event, field, interface, method, portable executable file module, parameter, property, return value, struct, or another attribute.

Information provided by an attribute is also known as metadata. metadata can be examined at run time by your application to control how your program processes data, or before run time by external tools to control how your application itself is processed or maintained. for example,. NET Framework predefines and uses attribute types to control run-time behavior, and some programming versions use attribute types to represent language features not directly supported by. NET Framework common type system.

Attribute Class. "Xml: space =" preserve "> All attribute types derive directly or indirectly from the Attribute class. attributes can be applied to any target element; multiple attributes can be applied to the same target element; and attributes can be inherited by an element derived from a target element. the AttributeTargets class can specify the target element to which the feature applies. "Xml: space =" preserve "> Use the AttributeTargets class to specify the target element to which the attribute is applied.

Attribute Class provides a simple way to retrieve and test custom features. "Xml: space =" preserve "> The Attribute class provides convenient methods to retrieve and test custom attributes. application features and use features to expand metadata. "Xml: space =" preserve "> For more information about using attributes, see Applying Attributes and Extending Metadata Using Attributes.

The Attribute class can associate the target element with a predefined information or user-defined information. The target element can be assembly, class, constructor, delegate, enum, event, field, interface, method, executable file module, parameter, property, return value, struct or other attributes. The information provided by Attribute is also called metadata ). Metadata can be used to control how your program data is accessed at runtime, or to control how your program is processed or deployed through additional tools before running. For example, if. NET Framework is pre-defined and attribute is used to control runtime behaviors, some programming languages use the attribute type to describe the language features that are not directly supported by the type in. NET Framework. All Attribute types are inherited directly or indirectly from the Attribute class. Attribute can be applied to any target element. multiple attributes can be applied to the same element. Attribute classes provide traversal methods to retrieve and test custom attributes.
Related Article

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.