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

相关推荐
星幻元宇VR3 分钟前
消防安全警示教育展厅设备【消防标识互动体验系统】
科技·学习·安全
我有满天星辰17 分钟前
【Dart 语言学习教程 】 第二章:面向对象编程
学习·flutter·dart
迷枫71218 分钟前
DCA 考试重点初版
学习
留白_23 分钟前
numpy学习
学习·numpy
花岛溯24 分钟前
AI产品经理学习 DAY4 · Cursor 生成figma 原型
学习·产品经理·figma
-To be number.wan24 分钟前
计算机组成原理 | Cache替换算法
学习·计算机组成原理
kgduu1 小时前
cosmos学习笔记
笔记·学习
AI_零食1 小时前
鸿蒙PC Electron跨平台应用开发:辗转相除法计算器实现详解
前端·学习·华为·electron·开源·鸿蒙·鸿蒙系统
weixin_428005301 小时前
C#调用 AI学习从0开始-第2阶段(Function Calling+工具调用智能体)-第9天实战
人工智能·学习·ai·c#·functioncalling
SNSZR12 小时前
2026 AI实操五大学习思路:破解碎片化自学无法落地商用项目的核心痛点
人工智能·学习