What is an attribute and how can it be applied?
An attribute is a special type that the C# compiler understands. It can be used to associate metadata to assemblies, types, and any member of a type. During compilation, the compiler will pick up the attributes and add them to the compiled assembly as metadata. You can place more than one attribute on every item.
Creating your own custom attribute is as simple as this:
public class CustomAttribute : Attribute { }
And then using it is done as follows:
[Custom] public class MyClass { }
Notice that you create the attribute with the Attribute postfix in the name. While using it, you don’t need it and you only have [Custom]. The C# compiler has a convention built into it saying you have to have the postfix, but it will ignore it when it’s used. This is a little bit weird and definitely violates the principle of least surprise.
The nice thing about attributes is that they live outside the scope of the element...