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

相关推荐
min(a,b)1 小时前
学习第 4 天:面向对象与异常处理
python·学习·学习方法
一只小菜鸡..1 小时前
南京大学 操作系统 (JYY) 学习笔记:进程地址空间与内存“外挂”魔法
笔记·学习
tju新生代魔迷2 小时前
Verilog语言学习(一)
学习
一只小菜鸡..3 小时前
南京大学 操作系统 (JYY) 学习笔记:访问操作系统的对象与“一切皆文件”
笔记·学习
IT空门:门主5 小时前
Python 基础语法学习路线图
网络·python·学习
寒月小酒8 小时前
第五章 生成集成 和第六章 RAG评估(all-in-rag学习)
数据库·学习
魔城烟雨8 小时前
从零开始学习betaflight《5-坐标系》
学习
笔夏8 小时前
【移芯平台CAT1模组】烧写固件
stm32·单片机·学习
憧憬成为java架构高手的小白8 小时前
黑马八股--spring框架学习
java·学习·spring
晓梦林9 小时前
[极客大挑战 2019]PHP学习笔记
笔记·学习·php