public static string GetGenericTypeName <TCommand>(this IRabbitCommandHandler <TCommand> handler) where TCommand : ICommand { foreach (Type intType in handler.GetType().GetInterfaces()) { if (intType.IsGenericType && intType.GetGenericTypeDefinition() == typeof(IRabbitCommandHandler <>)) { return(intType.GetGenericArguments()[0].Name); } } throw new InvalidOperationException(string.Format("Handler {0} had not correct generic interface", handler.GetType().Name)); }
public static TCommand GetData <TCommand>(this IRabbitCommandHandler <TCommand> handler, byte[] body) where TCommand : ICommand { string jsonBody = Encoding.UTF8.GetString(body); return(JsonSerializer.DeserializeFromString <TCommand>(jsonBody)); }