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

相关推荐
Z21-X13 小时前
云原生运维学习笔记:Kubernetes 自动扩缩容与资源管控实战
运维·笔记·学习·云原生·kubernetes
可涵不会debug13 小时前
ChatServer 模块学习笔记:HTTP 接入层、多线程与流式响应
笔记·学习·http
console.log('npc')1 天前
Python第9课 类学习笔记,前端js语法对照
前端·python·学习
艾莉丝努力练剑1 天前
【AI大模型接入SDK】解决Unicode码转化以及界面变形问题
前端·c++·人工智能·学习·安全·架构
旖旎夜光2 天前
【C 语言】(二)模拟实现 strlen、strcpy、strcmp、strstr、memcpy、memmove
c语言·开发语言·笔记·学习
大连好光景2 天前
腾讯云 ADP 前沿部署工程师 (FDE) 学习笔记(二)
笔记·学习·agent开发平台·adp·实战练习
IT空门:门主2 天前
LangChain4j 1.24.0 深度解读:新特性、版本对比与学习路线
java·学习
Shadow(⊙o⊙)2 天前
一年间学习的总结与成长记录——记录自己的18岁
学习
 梦晓天明2 天前
1.Spring学习笔记_IOC入门案例
笔记·学习·spring
sharemylove2 天前
Java 异常处理 学习笔记
java·开发语言·经验分享·笔记·学习