M
madks13
Guest
So i want to find all objects implementing a generic interface with 2 parameters (IRequestHandler<,>). Since i'm using a test project, there are only a few classes, among which, 2 that implement said interface.
The code to check for the interface is as follows :
assembly.GetTypes().Where(t => t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRequestHandler<>)) && !t.IsAbstract && !t.IsInterface).ToList();
This returns an empty list.
When debugging, i see the 2 classes i want found in the list of assembly types. When i check the interface types i see the following :
On the objects implementing the interface :
MediatR.IRequestHandler`2, MediatR, Version=8.0.1.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2
And typeof returns :
MediatR.IRequestHandler`1, MediatR, Version=8.0.1.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2
These come from the AssemblyQualifiedName property. I'm not sure if the IRequestHandler`1 and IRequestHandler`2 are the difference causing the problems, but i can't see anything else that differs.
Is this a bug or am i doing something wrong?
P.S. : I read the documentation here MicrosoftDoc and from my understanding the comparison line should work.
Continue reading...
The code to check for the interface is as follows :
assembly.GetTypes().Where(t => t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRequestHandler<>)) && !t.IsAbstract && !t.IsInterface).ToList();
This returns an empty list.
When debugging, i see the 2 classes i want found in the list of assembly types. When i check the interface types i see the following :
On the objects implementing the interface :
MediatR.IRequestHandler`2, MediatR, Version=8.0.1.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2
And typeof returns :
MediatR.IRequestHandler`1, MediatR, Version=8.0.1.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2
These come from the AssemblyQualifiedName property. I'm not sure if the IRequestHandler`1 and IRequestHandler`2 are the difference causing the problems, but i can't see anything else that differs.
Is this a bug or am i doing something wrong?
P.S. : I read the documentation here MicrosoftDoc and from my understanding the comparison line should work.
Continue reading...