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

相关推荐
重生之我是萧炎19 小时前
PR安装教程,Adobe Premiere Pro安装教程(含安装包),仅供学习使用
学习·adobe
蒸蒸yyyyzwd20 小时前
深搜广搜学习笔记
笔记·学习
叼烟扛炮21 小时前
[LangChain] 学习笔记(13):并发不是越大越好——batch / gather / 信号量 / 配额治理
笔记·学习·langchain
渣渣盟1 天前
狂命爆肝99天,共52K字的JAVA学习笔记奉上,JAVA从入门到精通一文搞定,一文在手JAVA无忧
java·笔记·学习
叼烟扛炮1 天前
[LangChain] 学习笔记(09):工具(Tool)定义与调用闭环 · 理论+实战完整版
笔记·学习·langchain
个 人 练 习 生1 天前
C++:从零基础到深入了解vector的使用
开发语言·c++·经验分享·学习·程序人生·stl
Rabitebla1 天前
【Linux操作系统】 文件篇(一):文件描述符与 Linux 文件管理机制
linux·网络·c++·笔记·学习
旖旎夜光2 天前
【C++ 基础入门】智能指针:RAII、unique_ptr 与 shared_ptr 循环引用
c++·笔记·学习·智能指针
zdr尽职尽责2 天前
终端工具凭空消失:Codex + GPT-6 的一次完整排障复盘
数据库·gpt·学习·ai
蒸蒸yyyyzwd2 天前
计算机网络后端面试错题
笔记·学习