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

相关推荐
新手unity自用笔记23 分钟前
unity基于Socket的网络学习
网络·网络协议·学习·unity·c#·游戏引擎
zyf10441627 分钟前
暑期实践日志 Day32:完成第六章字幕添加,推进工作
学习·计算机网络·剪辑·暑期实践·课题任务
小雪崩42 分钟前
嵌入式学习 day27:标准IO
linux·c语言·学习
hsjiasb1 小时前
FreeRTOS学习(三十五)——系统架构综合项目
学习·学习笔记·freertos
YM52e1 小时前
语言地区选择器-鸿蒙ArkTS国际化页面设计
学习·华为·harmonyos
不是光头 强1 小时前
Java 后端 AI 技术选型与学习路线
java·人工智能·学习
cloudification2 小时前
virtual
学习
MartinYeung52 小时前
[论文学习]δ-STEAL:基于本地差分隐私的大语言模型窃取攻击
网络·学习·语言模型
paopaokaka_luck2 小时前
基于springboot3+vue3的文山民族文化资源展示与推广平台(协同过滤算法、Echarts 图形化分析)
java·前端·spring boot·学习·echarts
wuhuhuan4 小时前
【JMeter 学习打卡 Day 4】多用户登录 + 动态 token 关联
学习·jmeter