I'm trying to get all types with the code below based on these topics:
- Get Method Details using reflection and decorated attribute
- Creating Custom Attributes (C# and Visual Basic)
So I have this attribute:
public class DataLayerInterfaceAttribute : System.Attribute
{
public DataLayerInterfaceAttribute() { }
}
And I have this interface:
[DataLayerInterfaceAttribute]
interface IInterface
{
void Method(string param);
}
Finally I want to get the interface type:
var types = from type in assembly.GetTypes()
where Attribute.IsDefined(type, typeof(DataLayerInterfaceAttribute))
select type;
I already tested with this:
var types = from type in assembly.GetTypes()
where type.GetCustomAttributes(type,true).Length > 0
select type;
But the result for both is empty and I dont know why.
EDIT
I'm getting the assembly like this:
string assemblyName = System.Reflection.Assembly.GetExecutingAssembly().Location;
byte[] assemblyBytes = File.ReadAllBytes(assemblyName);
Assembly assembly = Assembly.Load(assemblyBytes);