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

相关推荐
hsjiasb16 小时前
FreeRTOS学习(二十七)——任务栈与栈溢出检测
开发语言·stm32·学习·学习笔记·freertos
小弥儿16 小时前
GitHub今日热榜 | 2026-08-16:大模型微调与编码工具扎堆
学习·开源·github
xian_wwq18 小时前
【学习笔记】光伏“四可”装置纵密模块--配置方法和原理
笔记·学习
min(a,b)19 小时前
学习第17天:Agent Memory 与 MCP 协议
python·学习
lifallen20 小时前
模型不是函数:claude-cookbooks/misc 十四篇的公共底层
人工智能·学习·ai·ai编程
lucky_syq21 小时前
第5篇 · S1·下:前沿架构:MoE、Reasoning 模型、长上下文、多模态、SSM/Mamba 与模型谱系
人工智能·学习·架构
日拱一卒的小田21 小时前
ZYNQ学习笔记3-ZYNQ的IIC控制器1
笔记·单片机·学习
xiaoxiangsiyan1 天前
RHCE2026完整版全知识点清单
运维·网络·学习·自动化·rhce
Titan20241 天前
Linux网络基础知识
linux·服务器·网络·c++·学习
m4Rk_1 天前
【论文阅读】Agent 记忆机制(41):Agentic Plan Caching——将历史执行轨迹转化为可复用的计划记忆
论文阅读·人工智能·学习·开源·github