In order to create a simple event bus to implement a communication infrastructure for microservice I hit this question:
How can I invoke multiple Action with different generic types?
In order to create a simple event bus to implement a communication infrastructure for microservice I hit this question:
How can I invoke multiple Action with different generic types?
My solution for this issue:
void Main()
{
    var data = new object[] { new ProviderA(), new ProviderB() };
    var events = new List<object> {
        new Action<ProviderA>(provider => provider.Fire()),
        new Action<ProviderB>(provider => provider.Fire())
    };
    Invoke(events[0], data);
    Invoke(events[1], data);
}
void Invoke(object action, object[] data)
{
    var genericActionType = action.GetType().GenericTypeArguments[0];
    var dataObject = data.First(f => f.GetType() == genericActionType);
    var genericAction = typeof(Action<>).MakeGenericType(dataObject.GetType());
    genericAction.GetMethod("Invoke").Invoke(action, new object[]{ dataObject });
}
public class ProviderA
{
    public void Fire() { Console.WriteLine("Provider A fired"); }
}
public class ProviderB
{
    public void Fire() { Console.WriteLine("Provider B fired"); }
}