/// <summary> /// Used for weakly-typed requests. Arguments sent in this way are matched by name only, the order isn't used. /// </summary> /// <param name="targetMethod">The name of the method to be called.</param> /// <param name="typeName">The type on which to call the method.</param> /// <param name="arguments">A dictionary of arguments to be supplied to the method, where the key is the name of the argument.</param> public HttpServiceRequest(string targetMethod, string typeName, Dictionary <string, object> arguments) : this(arguments) { if (targetMethod == null) { throw new ArgumentNullException(nameof(targetMethod)); } Target = new InvocationTarget(targetMethod, typeName); foreach (var argument in arguments) { Arguments.Add(argument.Key, argument.Value); } }
/// <summary> /// Used for strongly-typed requests. Arguments sent in this way are matched by order only, the name isn't used. /// </summary> /// <param name="targetMethod">The <see cref="MethodInfo"/> of the method to be called.</param> /// <param name="arguments">An array of arguments to be supplied to the method, where the position of the elements match the position of the arguments.</param> public HttpServiceRequest(MethodInfo targetMethod, object[] arguments) : this(arguments) { if (targetMethod == null) { throw new ArgumentNullException(nameof(targetMethod)); } var parameters = targetMethod.GetParameters(); if (arguments.Length < parameters.Count(a => a.IsOptional == false)) { throw new ArgumentException("An incorrect number of arguments was supplied for the specified target method.", nameof(arguments)); } Target = new InvocationTarget(targetMethod, parameters); for (int i = 0; i < arguments.Length; i++) { Arguments.Add(parameters[i].Name, arguments[i]); } }