Intrinsic and Custom Attributes
.NET framework is littered with attributes and CLR (common language runtime)
provides a set of intrinsic attributes that are integrated into the framework.
Serializable is an example of intrinsic attribute. Besides the framework supplied
attributes, you can also define your own custom attributes to accomplish your
goal.
When do you define your custom attributes? Attributes are suitable when you
have crosscutting concerns. Object Oriented (OO) methodology lacks a modular
approach to address crosscutting concerns in objects. Serialization is an example
of crosscutting concern. Any object can be either serializable or non-serializable.
If, for example, halfway in the development phase you realize that you need
to make a few classes serializable, how do you do that? In .NET, you only need
to mark them as serializable and provide methods to implement a serialization
format. Other crosscutting concerns can be security, program monitoring and
recording during debugging, data validation, etc. If you have a concern that
affects a number of unrelated classes, you have a crosscutting concern and attributes
are excellent candidates to address crosscutting concerns.