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

相关推荐
Byron__8 小时前
AI学习_06_短期记忆与长期记忆
人工智能·python·学习
试剂界的爱马仕10 小时前
Anti-mouse PD-1 mAb (Clone RMP1-14) 与 Axitinib 小鼠实验使用方案整理汇总
大数据·人工智能·深度学习·学习
Gp7HH6hrE10 小时前
OpenAI 与 Anthropic 开放公共学习平台
人工智能·学习·chatgpt
kaixin_learn_qt_ing11 小时前
2026.7.3---学习记录
学习
99乘法口诀万物皆可变12 小时前
PcanToVectorXL_V01:打通 Vector 与 PCAN 的双向 CAN/CAN‑FD 桥梁
c++·学习
MartinYeung512 小时前
[论文学习] CAMIA:下文感知成员推理攻击
人工智能·深度学习·学习
secondyoung12 小时前
Cortex-R52学习:存储系统
arm开发·单片机·学习·arm
科技IT杂谈13 小时前
2026年智能体与定制工具平台观察:五个平台的路径与场景
学习
New农民工13 小时前
射频芯片学习-Lora包参配置
学习
Turbo正则14 小时前
群论学习入门 | 群论与李群的基本概念
人工智能·学习·算法·抽象代数