List all .NET Attributes in the Loaded Assemblies

Here’s how to list all the .NET Attributes in the loaded assemblies.

static void Main(string[] args)
{

var attributes = from assembly in AppDomain.CurrentDomain.GetAssemblies()
from exptype in assembly.GetExportedTypes()
where typeof(Attribute).IsAssignableFrom(exptype)
select exptype;

foreach (var nm in attributes)
{
Console.WriteLine("Attribute Name: {0} \nFullName: {1}",
nm.Name, nm.FullName);
Console.WriteLine("-------------------------------------------");
}

Console.ReadLine();
}




Note: The results may vary on your machine. Since we are referring to the GetExportedTypes() which returns type visible outside the assembly, you can get different results by adding new references (Right click project > Add Reference ) or by changing the access modifiers of the types.

OUTPUT

image

Check out Attributes Every .NET Developer Should Know About

and

Longest and Shortest Type Name in .NET 4.0 using LINQ






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: