/// <summary> /// Initializes a new instance of <see cref="WampRequestMapper{TMessage}"/> /// </summary> /// <param name="type">The type to map WAMP requests its methods.</param> /// <param name="formatter">A <see cref="IWampFormatter{TMessage}"/> used /// to check if a parameter can be binded to given type.</param> public WampRequestMapper(Type type, IWampFormatter <TMessage> formatter) { mFormatter = formatter; mMapping = BuildMapping(type); mMissingMethod = FindMissingMethod(type); }
private Func <object, object[], object> BuildAction(WampMethodInfo wampMethod) { Func <object, object[], object> method = MethodInvokeGenerator.CreateInvokeMethod(wampMethod.Method); return(method); }
private bool CanBind(WampMethodInfo wampMethodInfo, TMessage[] arguments) { return(wampMethodInfo.Method.GetParameters() .Where(x => !x.IsDefined(typeof(WampProxyParameterAttribute), true)) .Zip(arguments, (parameterInfo, argument) => new { parameterInfo, argument }) .All(x => mFormatter.CanConvert(x.argument, x.parameterInfo.ParameterType))); }
private object[] ConvertArguments(WampMessage <TMessage> message, WampMethodInfo method) { ParameterInfo[] parametersList = method.ParametersToConvert; TMessage[] arguments = message.Arguments; IEnumerable <TMessage> relevantArguments = arguments; if (method.HasParamsArgument) { relevantArguments = relevantArguments.Take(parametersList.Length - 1); } List <object> converted = parametersList.Zip(relevantArguments, (parameter, argument) => DeserializeArgument(parameter, argument)) .ToList(); if (method.HasParamsArgument) { IEnumerable <TMessage> otherArgumets = arguments.Skip(parametersList.Length - 1); converted.Add(otherArgumets.ToArray()); } return(converted.ToArray()); }
public Action <TClient, WampMessage <TMessage> > BuildMethod(WampMethodInfo wampMethod) { Func <object, object[], object> action = BuildAction(wampMethod); return((client, message) => { object[] arguments = GetArguments(client, message, wampMethod); object instance = GetInstance(client, message, wampMethod); action(instance, arguments); }); }
private object[] InnerGetArguments(TClient client, WampMessage <TMessage> message, WampMethodInfo method) { List <object> methodArguments = new List <object>(method.TotalArgumentsCount); if (method.HasWampClientArgument) { methodArguments.Add(client); } if (method.IsRawMethod) { methodArguments.Add(message); } else { methodArguments.AddRange (ConvertArguments(message, method)); } return(methodArguments.ToArray()); }
protected virtual object[] GetArguments(TClient client, WampMessage <TMessage> message, WampMethodInfo method) { return(InnerGetArguments(client, message, method)); }
// Maybe these should be in a seperated interface. protected virtual object GetInstance(TClient client, WampMessage <TMessage> message, WampMethodInfo method) { return(mInstance); }