The topics described here concentrates fully on pure .Net Framework, describing actual meaning of some programming concepts, FCL and best practices. However you will be using these concepts in all . Net framework compatible languages like Microsoft visual basic .net (VB.Net) or C# .Net (csharp.Net) to build a web application (Asp.Net) or Desktop applications (winforms .net) or Web/Windows services

This blog has moved!

You will be automatically redirected to the new address. If that does not occur, visit
and update your bookmarks.

Tuesday, December 11, 2007

Attributes in .Net

So what is a c# attribute or what is an attribute in .Net? Yes, this is one of the main facilities available in .Net which paves the way to declarative programming. When we say declarative, it is when you use data rather than write source code to instruct your application or component to do something like how to behave in a situation or what characteristic these object (.net data type) posses etc

Attributes defines or demands some particular characteristics of a .Net class. If you declare an attribute on a class, it is like either notifying or demanding the CLR that this class needs to be treated in some particular manner or that class is having some particular characteristic

For e.g.:-
Applying the [Serializable] attribute to a class informs the execution runtime that an instance's fields can be serialized and desterilized

Applying the [DllImport] attribute to a method notifies the CLR that the implementation of the method is actually in unmanaged code contained in the specified DLL.

Applying the [AssemblyVersion] attribute to an assembly sets the version number of the assembly which is just a characteristic property used for identification

These attributes are recorded in that particula .net type’s metadata table. This extensible metadata information can be queried at run time to dynamically alter the way code executes

There are so many such in-built attributes available in .Net. All of them derives or inherits from System.attribute. This helps us in building custom attributes. We can make a class inherit from System.attribute and define our own attribute rules or behaviors

No comments: