I can see many similar questions, but I can't find a solution covering this case:
I have the following code:
Service.AddQuery(T => new ServiceFactory.New()
.AddQueryType<Test>()
.Register(T)
.Create());
public class Test
{
...
}
it's not my code and it can't be changed.
Since the system has a plugin architecture, I cannot know the Test type ahead of time, so I need to do something like:
RegisterService(Type MyQueryType)
{
Service.AddQuery(T => new ServiceFactory.New())
.AddQueryType<MyQueryType>()
.Register(T)
.Create());
}
but I can't find how to make this work.
I tried to pass typeof, I tried to create an instance with Activator.CreateInstance, etc and I can't find how to make this happen.
How can this be done?
Edit:
This was flagged as a possible duplicate of How do I use reflection to call a generic method?, although the first line of my question said:
I can see many similar questions, but I can't find a solution covering this case
The answer in the other question is calling one method based on its name. Here the place to inject the type is in the middle of a chain (between AddQuery and Register) and I don't see how the method in that answer could work. But I'd be happy to be proven wrong.