C ා common attributes

Time:2020-12-2

catalog
  • Specifies the property methodimplattribute of the method implementation
  • Mark program element obsoleteattribute that is no longer used
  • Specifies the descriptionattribute for the property or event
  • To be continued

With attributes, you can effectively associate metadata or declarative information with code (assemblies, types, methods, properties, and so on). After you associate a feature with a program entity,Reflection can be used to query the feature at run time
In C ා,Specify an attribute by enclosing the attribute name in square brackets (()) and placing it above the declaration of the entity to which the attribute is applied

By convention, all attribute names end with attribute. However, several runtime oriented languages (such as visual basic and C ා)You do not need to specify the full name of the attribute。 For example, to initialize System.ObsoleteAttribute Simply refer to it as an obsolete.

Specifies the property methodimplattribute of the method implementation

Synchronization method

  • [MethodImplAttribute( MethodImplOptions.Synchronized )]LabelApply to instance method, equivalent toLock the current instance lock(this)。
  • [MethodImplAttribute( MethodImplOptions.Synchronized )]LabelApply to static methods, equivalent toLock the current type。 If withdraw is a static method, it is equivalent to lock (typeof (account))

Mark program element obsoleteattribute that is no longer used

Outdated warning

  • [obsoleteattribute (“obsolete method, attribute, class, etc., please use new XXX method, attribute, class, etc.)”,false)]
  • [obsoleteattribute()] or [obsoleteattribute]

Obsolete error

  • [obsoleteattribute (“obsolete method, attribute, class, etc., please use new XXX method, attribute, class, etc.)”,true)]

Specifies the descriptionattribute for the property or event

DescriptionAttributeMore Chinese comments for displaying enumeration variables, reflect the value of descriptionattribute of enumeration elements to the interface.

To be continued

Recommended Today

Angularjs instruction practice

Directives is the most important part of all angularjs applications. Although angularjs has provided very rich instructions, it is often necessary to create application specific instructions. This tutorial will show you how to customize instructions and how to use them in real projects. At the end of this article, I’ll show you how to use […]