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
Check out Attributes Every .NET Developer Should Know About
and
Longest and Shortest Type Name in .NET 4.0 using LINQ
Tweet
No comments:
Post a Comment