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

相关推荐
晓梦林6 小时前
BUUCTF findKey-学习笔记
笔记·学习
0566466 小时前
agent学习Day15——SQLAlchemy 查询过滤、分页与历史列表接口
python·学习·fastapi
炎武丶航9 小时前
汽车功能测试学习(1):FCW前方碰撞预警
功能测试·学习·汽车
qq_1851986914 小时前
SpingBoot3入门学习一
学习
噗噗夹的TA之旅14 小时前
Shader 学习 21:自定义 Render Feature
学习·游戏·unity·c#·游戏引擎·图形渲染
码农小韩15 小时前
AIAgent应用开发——大模型理论基础与应用(七)
python·学习·ai·大模型·agent
流云鹤16 小时前
05Java学习day(5)
java·学习
only-lucky17 小时前
QML深入学习五(Controls模块)
前端·javascript·学习
Yolanda_202217 小时前
Python学习-第九部分-错误处理与异常处理
开发语言·python·学习
一只小菜鸡..17 小时前
南京大学 操作系统 (JYY) 学习笔记:CPU 的局限、GPU 与 AI 时代的算力革命
人工智能·笔记·学习