All built-in .Net attributes

I used AppDomain.CurrentDomain.GetAssemblies()to list all the assemblies, but how do I list all the built-in attributes in .NET 2.0 using C #?

+5
source share
1 answer

Note that it AppDomain.GetAssemblies()will only list loaded assemblies ... but then this is easy:

var attributes = from assembly in assemblies
                 from type in assembly.GetTypes()
                 where typeof(Attribute).IsAssignableFrom(type)
                 select type;

.NET 2.0 version (not LINQ):

List<Type> attributes = new List<Type>();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
    foreach (Type type in assembly.GetTypes())
    {
        if (typeof(Attribute).IsAssignableFrom(type))
        {
            attributes.Add(type);
        }
    }                   
}
+15
source

All Articles