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")

相关推荐
m4Rk_44 分钟前
【论文阅读】Agent 记忆机制(94):MemGen——在推理过程中动态生成并织入潜在记忆
论文阅读·人工智能·学习·开源·github
晓德1 小时前
0、LLM大模型安全学习系列(启)
学习·安全
Titan20241 小时前
MySQL索引学习笔记
笔记·学习·mysql
JWASX2 小时前
Java 转 go 学习 - kitex(5)
学习·golang
AOI小白新手上路2 小时前
VDMamba·AutoDL 复现笔记 · 学习笔记
笔记·学习
~kiss~2 小时前
LangGraph ~ 为图添加跨线程持久化
学习
xianrenli383 小时前
水肺潜水学习
学习
凌云若寒4 小时前
BarTender提示#807错误:无法在拥有其他许可证的Licensing Service上激活节点锁定的 Professional 版许可证 的解决办法
运维·服务器·前端·学习·软件需求
爱吃苹果的日记本5 小时前
离散数学第七课
学习·离散数学
迪丽热爱5 小时前
多媒体应用31-914(计算机硬件与体系结构)
学习