public void Handle <T>(T msg) { var args = msg as BasicDeliverEventArgs; if (args == null) { throw new InvalidCastException($"Could not cast {typeof(T).Name} to BasicDeliverEventArgs"); } if (string.IsNullOrEmpty(args.BasicProperties.Type)) { throw new Exception("No type set on message"); } var type = Type.GetType(args.BasicProperties.Type); if (type == null) { throw new Exception($"Unable to get type for {args.BasicProperties.Type}"); } var data = _serializerFactory.DeserializeToType(args, type); _dispatcher.Dispatch(Convert.ChangeType(data, type)); }