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

相关推荐
浔溺4 分钟前
al+大数据每日学习笔记36
大数据·笔记·学习
传奇开心果编程18 分钟前
【Xilem基础语法学与练】第8课:条件渲染(one_of)
学习·rust·前端框架
小雪崩24 分钟前
嵌入式学习 day44:51单片机入门
嵌入式硬件·学习·51单片机
浔溺36 分钟前
al+大数据每日学习笔记35
大数据·笔记·学习
kyrie_sakura1 小时前
MySQL学习笔记4 -- select的7大子句,子查询
笔记·学习·mysql
UIU1141 小时前
补码运算与整数溢出(上
学习·c#·补码·补码运算
词却2 小时前
OpenCV学习:人脸识别
人工智能·opencv·学习
xqqxqxxq3 小时前
AI Agent学习:第四章小结及八道思考题(李博杰《深入理解 AI Agent》第四章观后总结)
大数据·人工智能·学习
Willliam_william3 小时前
QEMU学习之路(13)— 在BusyBox中安装pciutils
学习
小白的后端世界3 小时前
数据分析基础学习
人工智能·学习·数据分析