For the complete documentation index, see llms.txt. This page is also available as Markdown.

Annotation Utilities

AnnotationUtility member annotation reading tool.

AnnotationUtility is used to read display-related comments from type members, including classification, display name, and description.

method
Description

GetCategory

GetDisplayName

Read DisplayNameAttribute Source or DisplayAttribute.Name.

GetDescription

Read DescriptionAttribute Source or DisplayAttribute.Description.

Source: framework/externals/aliyun/src/Telecom/PhoneTransmitter.cs (excerpt; see source for context).

PhoneTransmitter.cs
_descriptor = new TransmitterDescriptor(this.Name, AnnotationUtility.GetDisplayName(this.GetType()), AnnotationUtility.GetDescription(this.GetType()));

From Annotations to Display Metadata

The above is the actual code for the framework Aliyun PhoneTransmitter to create the transmitter descriptor. This type uses the DisplayName and Description attributes to declare the resource key. AnnotationUtility reads the annotations and cooperates with the resource mechanism to obtain the title and description. See template sender for a complete example, and Resource management for resource search. Discussions' model fields and enumerations also rely on resource descriptions, but without this sender code.

When to Use

When the description of a model, command, or configuration item is maintained uniformly by a type declaration, reading the annotation can avoid saving the name repeatedly in each interface. Annotations are responsible for displaying metadata, do not participate in database column name matching, and cannot replace parameter verification. Missing annotations or resources should be handled according to the caller's display convention, and the returned title should not be used as a permission key or persistent identifier.

Last updated