装饰一个类或参数是什么意思? [英] What does it mean to decorate a class or parameter?

查看:77
本文介绍了装饰一个类或参数是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

装饰或向类或参数添加属性是什么意思?
目的是什么,什么时候可以做?

What does it mean to Decorate or add an attribute to a class or parameter?
What's the purpose and when would I do this?

欢迎使用资源链接和直接答案.

Links to resources and direct answers are welcome.

推荐答案

在C#中添加装饰器时,就像在类/方法中添加属性一样.将附加一个属性.

When You add decorator in C# it is like adding a property to the class/method. There will be an attribute attached to it.

如果编写单元测试,您将遇到像这样的简单装饰器TestMethod:

If You write Unit test You will meet a simple decorator TestMethod like that:

[TestMethod]
public void TestMethod1()
{
}

框架将使用装饰器来检查测试集中的测试方法.

The framework will use the decorators to check what test methods are in the test set.

您可以在此处

还有一篇很有趣的文章,内容关于写作自定义属性

There is another nice to read article about Writing Custom Attributes

装饰器不限于装饰器的"[]"形式.还有一种设计模式,以前其他人已经提到过.

Decorators are not limited to the '[ ]' form of decorators. There is also a design pattern for that, that was already mentioned before by others.

这篇关于装饰一个类或参数是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆