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

相关推荐
xianrenli383 小时前
DS5900作业之“氛围(Vibe)”背后的伦理
学习·ai编程·msai
iuu_star4 小时前
Python大模型智能学习平台——设计与实现(AI教学系统)
大数据·人工智能·python·学习
三品吉他手会点灯4 小时前
嵌入式机器学习 - 学习笔记1.2.3 - 机器学习软件框架
人工智能·笔记·嵌入式硬件·学习·机器学习
YangYang9YangYan5 小时前
2026数字经济专业毕业发展指南
物联网·学习
武陵悭臾6 小时前
Python应用开发学习:如何让随机数按一定比列出现
python·学习·random·概率·随机数
渣渣灰飞6 小时前
MySQL 系统学习 第六阶段:Redis + 缓存 + 高并发设计 第八章:Redis 高级应用
学习·mysql·缓存
Kobebryant-Manba6 小时前
学习Bert
学习·自然语言处理·bert
渣渣灰飞6 小时前
MySQL 系统学习 第六阶段:Redis + 缓存 + 高并发设计 第十章:Redis 综合企业项目实战
学习·mysql·缓存
xian_wwq7 小时前
【学习笔记】多模态部署:VLM、语音、视频理解(29/35)
笔记·学习·音视频
冷小鱼7 小时前
AI Agent的核心算法:自主学习与反思(Self-Reflection / Critique)
人工智能·学习·算法·自主学习·self-reflection·critique·反思