I have the following interface in an assembly Base.dll
public interface IMessageHander<in T>{
void Handle(T msg);
}
public class MyBase<TChild> where TChild: MyBase<TChild>{
private TChild Self => this as TChild;
void CallMethods(){
// how to call implemented interfaces handlers??
// Self.Handle(msg1);
// Self.Handle(msg2)
}
}
Someone references Base.dll and writes the following code
public class Msg1{}
public class Msg2{}
public class Msg3{}
public class MyHandler: IMessageHander<Msg1>,
IMessageHander<Msg2>,
IMessageHander<Msg3>
{
void Handle(Msg1 msg){}
void Handle(Msg2 msg){}
void Handle(Msg3 msg){}
}
In Base.Dll through reflection I'm able to find out what interfaces are implemented and what are their generic types being passed i.e. all the message types and their corresponding handlers. I want to be able to call them using the Expression.Lambda. How would I do that?
I don't want to use reflection which I already know. Please see this question for the background How to create object dynamically
I receive the object to be passed as message in the form of base object only.