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.


Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

No comments: