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

相关推荐
·醉挽清风·1 小时前
学习笔记—算法—算法题
笔记·学习·算法
a1117761 小时前
机器人导航入门指南(从 0 到 1)
笔记·学习·slam
范什么特西2 小时前
每日学习-01
学习
旺仔丶歪歪乐2 小时前
英语启蒙APP分级体系拆解:本土课标分级与海外原版分级有什么区别
人工智能·学习·web app
xian_wwq3 小时前
【学习笔记】开源 vs 闭源:Llama / Qwen / DeepSeek 生态博弈(34/35)
笔记·学习·开源
振浩微433射频芯片3 小时前
5个IO控制20个LED?查理复用实战拆解
网络·单片机·物联网·学习·智能家居
kitsch0x974 小时前
论文学习_MalSkillBench: A Runtime-Verified Benchmark of Malicious Agent Skills
学习
Z5998178414 小时前
c#软件开发学习笔记--分组、游标与临时表、分页
笔记·学习·c#
治愈系贝壳5 小时前
ARM ---day1
linux·arm开发·学习
qdprobot5 小时前
齐护AIOT科创社团学习套件桌面总程AiTall V3版人工智能Mixly图形化编程AI小智物联网AI具身智能应用椴木科创作品
人工智能·物联网·学习