public void GenerateResponse <TRequest, TResponse>(CommandRequestId id, Func <CommandRequestId, TRequest, TResponse> creator) where TRequest : ICommandRequest where TResponse : struct, IReceivedCommandResponse { if (!outgoingRequests.TryGetValue(id.Raw, out var request)) { throw new ArgumentException($"Could not find a request with request id {id}"); } var commandClass = ComponentDatabase.GetCommandMetaclassFromRequest <TRequest>(); if (typeof(TResponse) != commandClass.ReceivedResponse) { throw new ArgumentException($"Invalid response type {typeof(TResponse)}, expected {commandClass.ReceivedResponse}"); } CurrentDiff.AddCommandResponse(creator(id, (TRequest)request), commandClass.ComponentId, commandClass.CommandIndex); requestIds[typeof(TRequest)].Remove(id.Raw); outgoingRequests.Remove(id.Raw); }
public void GenerateResponses <TRequest, TResponse>(Func <CommandRequestId, TRequest, TResponse> creator) where TRequest : ICommandRequest where TResponse : struct, IReceivedCommandResponse { var ids = GetOutboundCommandRequests <TRequest>(); var commandClass = ComponentDatabase.GetCommandMetaclassFromRequest <TRequest>(); if (typeof(TResponse) != commandClass.ReceivedResponse) { throw new ArgumentException($"Invalid response type {typeof(TResponse)}, expected {commandClass.ReceivedResponse}"); } foreach (var id in ids) { var request = outgoingRequests[id.Raw]; CurrentDiff.AddCommandResponse(creator(id, (TRequest)request), commandClass.ComponentId, commandClass.CommandIndex); outgoingRequests.Remove(id.Raw); } requestIds[typeof(TRequest)].Clear(); }