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

相关推荐
是一个Bug3 小时前
Agent(智能体)应用 的入门学习路径
学习·机器学习
2301_809051143 小时前
Linux 网络编程 学习笔记
linux·网络·学习
eggcode4 小时前
【Qt学习】Linux(ARM架构)在线安装Qt6.x
linux·qt·学习·arm
_李小白6 小时前
【android opencv学习笔记】Day 26: 滤波算法之低通滤波与图像缩放插值
android·opencv·学习
Bechamz6 小时前
大数据开发学习Day43
大数据·学习
happymaker06269 小时前
SpringBoot学习日记——DAY06(整合MyBatisPlus的其他功能)
java·spring boot·学习
星夜夏空999 小时前
FreeRTOS学习(3)——FreeRTOS的移植与剪裁
学习
嵌入式×边缘AI:打怪升级日志10 小时前
硬件清单与学习进度存档
学习
Engineer邓祥浩11 小时前
软件设计师备考 第0章 题型分布、示例、学习路线
学习·职场和发展