C# attributes and how it works

Posted by Nagasundar_Tn under C# on 9/10/2014 | Points: 10 | Views : 1225 | Status : [Member] | Replies : 1
Please explain me why we should use attributes.. (other then declaraing obsolete)

say for example

public void Test()
//some logic

In the above code, I am using WebMethod() as attribute. I may have some properties like Description, Enable session etc., But my question how it is bounded with the particular class member (in our example Test()). Can I create object of attribute class? Is it like Inheritence?

Please explain



Posted by: Key123 on: 9/26/2014 [Member] Starter | Points: 25

Attributes is nothing but providing extra information about the class or members or interface. those information is added in the metadata. We can use those information when we work with Reflection.

2 types attributes,
Intrinsic - inbuilt in .Net
Custom - which we create our own.

For more details,
You can refer this book,
http://oreilly.com/catalog/progcsharp/chapter/ch18.html .


Nagasundar_Tn, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response