In the .NET Framework, attributes can be used for many reasons - for example,
Attributes allow you to add descriptions to classes, properties, and methods at design time, which can then be viewed at run time through reflection.
Consider this example:
Say you have a class that has a method from the old version that is still in use for some reason, and now you have created a new version of the class that uses the fantastic use of Generic List and LINQ and has a new method for a similar purpose. You would like developers to prefer the new one provided in a later version of your library. How do you do this? One way is to write to the documentation. It is best to use the attribute as follows.
public class AccountsManager { [Obsolete("prefer GetAccountsList", true)] static Account[] GetAccounts( ) { } static List<Account> GetAccountsList( ) { } }
If the obsolete method is used when compiling the program, the developer receives this information and decides accordingly.
AccountManager.GetAccounts () is deprecated: prefer GetAccountsList
We can also create and add Custom Attributes as required.
Link:
Hope this helps
Asad Butt Feb 19 '10 at 9:23 2010-02-19 09:23
source share