Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to decorate a class or parameter?

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.

like image 357
Mark G Avatar asked Jul 03 '15 13:07

Mark G


1 Answers

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

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.

You can check on the attribute here

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.

like image 163
ntohl Avatar answered Sep 21 '22 10:09

ntohl