Which .NET Attributes are my Assemblies Using?

An attribute describes a characteristic of some elements (classes, methods, fields) of a .NET program. Once associated with a program entity, the attribute can be queried at run time and used in any number of ways. In this post, we will learn how to list all the .NET Attributes that are used by the loaded assemblies in your program.

Use the following code:

image

The above code gets the assemblies that have been loaded into the execution context of the current application domain. We then retrieve the public types in this assembly and select all the attributes. A sample result is as shown below:

.NET attributes

Note: The results may not be the same on each machine. This is because we are referring to GetExportedTypes() which returns type visible ‘outside’ the assembly. So if you add new references to the project or by change the access modifiers of the types, you can get different results.





About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: