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

相关推荐
小向是个Der1 小时前
嵌入式进阶——MCU上电后的动作
c语言·单片机·mcu·学习·链接脚本
辣知5 小时前
辣知·化智93 被历史尘封的鬻子
学习
每天题库7 小时前
西藏安全员 A 证备考真题题库 强化重点知识刷题提升通过率
学习·安全·考试·题库·考证
Be for thing7 小时前
PyTorch基础|Tensor张量详解,张量创建、数据类型与常用操作
pytorch·学习·1024程序员节
前进的李工7 小时前
Agent 学习笔记 02:Harness 与工作流怎么理解
笔记·学习·agent·工作流·harness
m4Rk_8 小时前
【论文阅读】Agent记忆机制(114):MemoryTax——当 Agent 能自主搜索历史,专门的记忆系统还划算吗?
论文阅读·人工智能·学习·开源·github
程序员梅雨10 小时前
【从零开始学习数据仓库 | 第一篇】:维度建模理论
大数据·数据仓库·学习·阿里云·数据分析
keyipatience11 小时前
Git学习(4)Git分布式优势与实战配置全解析
git·学习
comyccccc14 小时前
STM32F407VET6核心板的部分电路绘制学习笔记
笔记·stm32·学习
叼烟扛炮14 小时前
Linux 学习笔记(三十六):并发进阶——读写锁 vs 自旋锁,到底怎么选?
linux·运维·服务器·笔记·学习