C# 特性 学习理解记录

在类或函数上一行xxx, 查看源码是 xxxAttribute

比如 NUnit 的单元测试 Test特性,

public class TestAttribute : NUnitAttribute, ISimpleTestBuilder, IApplyToTest, IImplyFixture,

可以在vs里测试》测试资源管理器》选中标注特性的函数进行单独测试

比如 System.ComponentModel.Description("描述类、函数的特性")

属于 public class DescriptionAttribute : Attribute

-也可以使用System.ComponentModel.DisplayName("123")

AttributeUsage(AttributeTargets.Class \| AttributeTargets.Method \| AttributeTargets.Property \| AttributeTargets.Event)

public class DisplayNameAttribute : Attribute

AttributeTargets.Class 这些事标识范围,DisplayName可以标识类,函数,属性,事件

场景:

函数返回的是英文,但特性标注了中文,可以用反射获取特性的描述,然后显示中英文;

System.ComponentModel.Description("猫")

public string getTheClass()

{

return cat;

}

自定义特性 :xxxAttribute 并继承atribute

标注:MyDescription(Name="商品名称3")

相关推荐
LccKyI17 分钟前
C#学习day06(方法/函数及其关键字,附思维导图)
经验分享·学习·c#
xian_wwq1 小时前
【学习笔记】Loop Engineering,从手动提示到目标驱动自动化-13/16
笔记·学习·自动化
殷忆枫1 小时前
K210 BOX学习笔记:环境搭建及模型训练部署
学习
qq_185198691 小时前
SpingBoot3入门学习-Web开发-三
java·数据库·学习
lifallen2 小时前
Avernet:Agent 的组织网络
人工智能·学习·ai·开源软件·ai编程
我爱cope2 小时前
【计算机网络 | 数据链路层2:差错检测与纠正:奇偶校验、校验和、CRC 分别怎么工作?】
网络·学习·计算机网络
知识分享小能手2 小时前
线性代数学习教程,从入门到精通,矩阵及其运算 — 完整知识点与详细推导(3)
学习·线性代数·矩阵
小弥儿3 小时前
Firecrawl:把整个网页变成 AI 可查询的数据库
数据库·人工智能·学习
woshihuanglaoshi3 小时前
鸿蒙老旧项目升级改造高级:API废弃迁移/ArkTS语法升级/架构重构策略/增量迁移/风险管控方案
学习·华为·重构·架构·harmonyos·鸿蒙
zhangrelay3 小时前
ROS 2 Lyrical 第2章 ROS 2系统架构与核心概念
linux·笔记·学习·ubuntu·ros2