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.

No comments:

Post a Comment