private void ProcessAttributeHandlers(ObjectToRoute p) { foreach (var handler in attributeHandlers) { handler.Validate(p); } }
private object[] ProvideMethodArguments(ObjectToRoute objectToRoute) { var methodParameters = objectToRoute.RouteRecord.SelectedMethod.GetParameters(); var resultList = new List <object>(methodParameters.Length); foreach (var parameter in methodParameters) { if (parameter.ParameterType.IsInstanceOfType(objectToRoute.Context)) { resultList.Add(objectToRoute.Context); } if (parameter.ParameterType.IsInstanceOfType(objectToRoute.Payload)) { resultList.Add(objectToRoute.Payload); } if (parameter.ParameterType.IsInstanceOfType(this)) { resultList.Add(this); } } return(resultList.ToArray()); }
public async Task RouteObjectAsync(object context, object routedObject) { var routingTable = GetSuitableRoutingRecords(context, routedObject); foreach (var record in routingTable) { var p = new ObjectToRoute(context, routedObject, record); await CallMethod(p); } }
private async Task CallMethod(ObjectToRoute objectToRoute) { ProcessAttributeHandlers(objectToRoute); var routeRecord = objectToRoute.RouteRecord; var methodArguments = ProvideMethodArguments(objectToRoute); var result = routeRecord.SelectedMethod?.Invoke(routeRecord.Processor, methodArguments); if (result is Task t) { await t; } }
private async Task CallMethod(ObjectToRoute objectToRoute) { ProcessAttributeHandlers(objectToRoute); var routeRecord = objectToRoute.RouteRecord; var methodArguments = ProvideMethodArguments(objectToRoute); try { var result = routeRecord.SelectedMethod?.Invoke(routeRecord.Processor, methodArguments); if (result is Task t) { await t.ConfigureAwait(false); } } catch (TargetInvocationException tie) { if (tie.InnerException != null) { throw tie.InnerException; } } }