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

注解工具

AnnotationUtility 成员注解读取工具。

AnnotationUtility 用于从类型成员读取显示相关注解,包括分类、显示名称和描述。

方法
说明

GetCategory

GetDisplayName

读取 DisplayNameAttribute 源码 或 DisplayAttribute.Name。

GetDescription

读取 DescriptionAttribute 源码 或 DisplayAttribute.Description。

来源:framework/externals/aliyun/src/Telecom/PhoneTransmitter.cs(节选;上下文见源文件)。

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

从注解到显示元数据

上面是框架 Aliyun PhoneTransmitter 创建发送器描述符的实际代码。该类型使用 DisplayName 和 Description 特性声明资源键,AnnotationUtility 读取注解并配合资源机制得到标题与说明。完整示例见模板发送器,资源查找见资源管理。Discussions 的模型字段和枚举也依赖资源描述,但没有这段发送器代码。

什么时候使用

当模型、命令或配置项的说明由类型声明统一维护时,读取注解能避免在每个界面重复保存名称。注解负责展示元数据,不参与数据库列名匹配,也不能代替参数验证。缺失注解或资源时应按调用方显示约定处理,不要把返回的标题用于权限键或持久标识。

相关资源

最后更新于