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

相关推荐
Be for thing10 分钟前
【嵌入式成长3】STC89C51外部中断|中断原理、寄存器、中断服务函数
单片机·嵌入式硬件·学习
优化Henry1 小时前
学习笔记之爱立信站点指向证书执行
运维·服务器·网络·笔记·学习·信息与通信
IT古董3 小时前
【WMS学习笔记系列】03-功能模块设计
笔记·学习·系统架构
zyf1044163 小时前
暑期实践日志 Day31:推进修改任务,完成第五章字幕添加
学习·计算机网络·剪辑·暑期实践·课题任务·课程视频
Canmag 兴隆磁性4 小时前
充磁的时候,磁铁里面到底发生了什么
学习·永磁材料·充磁·退磁
海兰5 小时前
【Kafka学习4】六大核心 API
学习·kafka·linq
知识分享小能手5 小时前
概理论与数理统计学习教程,从入门到精通,随机变量的数字特征 — 知识点总结与详细推导(7)
学习·机器学习·概率论
却道天凉_好个秋5 小时前
计算机网络:CDN
学习·音视频·cdn
圆奋奋5 小时前
FreeRTOS学习(十)- 最核心的内容:优先级抢占式调度 + 上下文切换
学习·freertos
程序猿炎义5 小时前
【llm-algo-leetcode学习笔记】显存与性能认知底座
笔记·学习·leetcode