Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 36,602 times

Contents

Related Categories

Attributed Programming in .NET Using C# - Intrinsic and Custom Attributes

ddutta

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.

Comments

  • Why attribute

    Posted by soruabhm on 03 May 2004

    Hi
    Good article.I have a qus here. I have used a ot of attributes and have tried writing mine as well. Now the basic qus of when to write one of our own is still a little difficult for me. I understa...

  • Serialization SOAP

    Posted by zaka48 on 06 Mar 2004

    how can I Add a reference to assembly System.Runtime.Serialization.Formatters.Soap.dll ???

  • Private attributes in .Net c#?

    Posted by nguyen422 on 10 Jan 2003

    This is a very good article.

    The example shown used public modifier for the class attributes, is there any way to get it to work with private/protected attributes? I tried the example code usin...

  • Attributes

    Posted by chinnu704 on 06 Jan 2003

    I have absolutely no knowledge of C# and attributes, but I could understand the article very easily. Good Write-up!

  • Drawbacks of attributed programming

    Posted by ghanshyam on 12 Nov 2002

    Well the attributed programming started from MIDL/COM programming and .NET also supports this concept widely.
    The advantages provided with attributed programming is amazing and simultaneously it has ...