I got the following code the works :
var library = Assembly.LoadFrom(libraryPath);
var namespaces = library.GetTypes().GroupBy(t => t.Namespace);
foreach (var typesInNamespace in namespaces)
{
foreach (var type in typesInNamespace)
{
[...]
}
}
But when I want to test if the current Type is an Attribute with this code :
var attributes = typesInNamespace.Where(t => t is System.Attribute);
or
if (type is System.Attribute)
they both fail and I have the following warning :
The given expression is never of the provided ('System.Attribute') type
The classes are defined like this :
class ImportableModelAttribute : Attribute
{
}
class ImportableAttribute : Attribute
{
}
To be honest, I was expecting a sort of API to deal with Attributes (something like if (type.IsAtteribute)) but I didnt find anything, that’s why I’m trying to do it this way !
A
Typeitself is never an attribute (in the same way thattypeof(string)isn’t a string), but I suspect you want:(Or put that in a lambda experssion, of course.)
See the docs for
Type.IsAssignableFromfor more information.