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

相关推荐
lengxuenong7 小时前
树状数组 · 信息学学习手册1-求和3个模板
c++·学习·算法·青少年编程
lanxiaoqing027 小时前
演讲训练的第一步:先敢说,再会说
人工智能·学习·学习方法·口才
m4Rk_9 小时前
【论文阅读】Agent记忆机制(109):MemComposer——用强化学习学会选哪些记忆、选多少以及怎样排序
论文阅读·人工智能·学习·开源·github
zhangdaliangmvp9 小时前
快速排序的学习理解:从基础分治到三路划分优化
c++·学习·算法
叼烟扛炮9 小时前
Linux 学习笔记(四):文件检索与管道重定向
linux·笔记·学习
王夏奇10 小时前
AI工具学习
网络·学习
Warolitbos10 小时前
【数据库】SQL进阶15题,窗口函数/索引/事务一页速查
数据库·sql·学习·mysql·面试
剑藏锋12 小时前
嵌入式学习(48)-大彩串口屏TFT指令解析
学习
cxyxixiy12 小时前
数智码力:数据核对不用人工比对,Python 快速完成多表格差异校验
开发语言·python·学习
懒大王952712 小时前
学习TS + ArkTS 快速入门
学习