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

相关推荐
2601_959383241 小时前
休学干预的“信任难题”,坤和静界·春藤计划怎么尝试破局
学习
tyqtyq223 小时前
HarmonyOS AI 应用开发实战:考研择校分析系统
人工智能·学习·考研·华为·生活·harmonyos
光影6273 小时前
MySQL基础入门
数据库·笔记·sql·学习·mysql·学习方法
海兰3 小时前
【实用程序】网页公开信息智能采集系统详细设计指南
人工智能·学习·自动化·采集信息
MartinYeung53 小时前
[论文学习]AgentDAM:自主Web Agent的隐私泄露评估
学习
光影6274 小时前
MySQL 进阶篇 —— 事务 / 外键 / 索引 / 高级查询
数据库·笔记·sql·学习·mysql
醉城夜风~5 小时前
MyBatis 基础CRUD全套实战学习笔记
笔记·学习·mybatis
blues92575 小时前
2026商超采购竹笋怎么选:从包装信息、货架周转到售后协同做判断
人工智能·科技·学习
Flandern11116 小时前
从“能跑”到“可运营”:Agent Harness 工程化建设指南
学习·agent·claudecode·harness
hj2862516 小时前
Shell 脚本完整学习笔记
chrome·笔记·学习