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

相关推荐
paopaokaka_luck8 小时前
基于springboot3+vue3的企业考勤管理系统(部门树递归、Echarts图形化分析)
开发语言·spring boot·学习·echarts·mybatis·需求分析·代码规范
minglie18 小时前
zynq高频小数据量PS闭环 抖动时间的测量
学习
long3168 小时前
MySQL 学习练习(配套 01 入门资料)
数据库·学习·mysql
梦雨生生9 小时前
java开发工具(学习第一天)
java·开发语言·学习
IT古董14 小时前
【MES学习笔记系列】05 - MES 数据库设计
笔记·学习·mes
LATASA15 小时前
【 从0到1构建 Agent Harness学习笔记】
网络·笔记·学习
weixin_4316004416 小时前
做 Agent 会用到的 Node API(3):异步与流
前端·学习·ai·agent·ai编程
Haku Coder16 小时前
0基础学习Git——基础篇
git·学习
70asunflower17 小时前
Triton 从 0 到 1 完整学习教程
学习·triton
天国梦17 小时前
2026年英语教学数字化工具深度测评:天学网、腾讯英语君、翼课网横向对比
人工智能·学习