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

相关推荐
solicitous1 天前
学习了解充电桩协议OCPP——J规范
学习
H__Rick1 天前
C51单片机学习-DAY3
单片机·学习·mongodb
yoothey1 天前
异常学习笔记:为什么自定义异常后还要 throw?
笔记·学习
WangN21 天前
【通识】宇树G1_29DOF速度跟踪训练—逐章学习手册
人工智能·python·学习·机器人·具身智能
lazy H1 天前
Spring Boot 项目如何连接 Redis?新手入门配置和常见错误总结
ide·spring boot·redis·后端·学习·intellij-idea
雾沉川1 天前
Flutter 入门开发环境完整搭建教程
学习·flutter
星夜夏空991 天前
STM32单片机学习(37) —— PWR和BKP
stm32·单片机·学习
万岳科技1 天前
教育培训系统开发流程详解:平台建设关键环节解析
数据库·后端·学习
fanged1 天前
高通学习14--RB5(TODO)
学习