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 小时前
鸿蒙HarmonyOS ArkTS原生学习:缩放手势实现 PinchToZoom 深度解析
学习·华为·harmonyos·鸿蒙
a1117761 小时前
SLAM 学习笔记(四)后端(KF BA)
笔记·学习
XGeFei2 小时前
【Django学习笔记】—— Django 高并发通俗讲解
笔记·学习·django
六点_dn2 小时前
Linux学习笔记-chmod命令
linux·笔记·学习
MartinYeung52 小时前
[论文学习]揭示大语言模型智能体记忆模块中的隐私风险
人工智能·学习·语言模型
心中有国也有家3 小时前
AtomGit Flutter 鸿蒙客户端:Flutter 鸿蒙应用的错误处理与优雅降级策略
学习·flutter·华为·harmonyos
2301_800256114 小时前
人工智能入门学习——ANN、CNN基本概念和考试核心代码
人工智能·学习·cnn
辞旧 lekkk4 小时前
CMake工程指南(一)
linux·运维·服务器·开发语言·qt·学习·萌新
db_murphy4 小时前
机器学习决策树的基尼系数是个啥?
学习·算法
心中有国也有家15 小时前
AtomGit Flutter 鸿蒙客户端: ChangeNotifier 模式
学习·flutter·华为·harmonyos