public RouteHandler(string service, string template, object instance, MethodInfo method) { this.Template = new UriTemplate("/" + service + (template == "*" ? "/*" : template)); this.Pattern = new UriPattern("/" + service + (template == "*" ? "/*" : template)); var methodParams = method.GetParameters(); TotalParams = methodParams.Length; WithStream = TotalParams != 0 && methodParams[TotalParams - 1].ParameterType == typeof(Stream); var lamParams = new ParameterExpression[2]; lamParams[0] = Expression.Parameter(typeof(string[]), "strArr"); lamParams[1] = Expression.Parameter(typeof(Stream), "input"); var expArgs = new Expression[TotalParams]; for (int i = 0; i < TotalParams; i++) { UppercaseArgumentOrder[methodParams[i].Name.ToUpperInvariant()] = i; ArgumentOrder[methodParams[i].Name] = i; if (i < TotalParams - 1 || !WithStream) { expArgs[i] = Expression.ArrayIndex(lamParams[0], Expression.Constant(i)); } else { expArgs[i] = lamParams[1]; } } var mce = Expression.Call(Expression.Constant(instance, instance.GetType()), method, expArgs); var lambda = Expression.Lambda <Func <string[], Stream, Stream> >(mce, lamParams); Invocation = lambda.Compile(); }
public RouteHandler( string service, string template, object instance, MethodInfo method, IServiceProvider locator, IWireSerialization serialization) { this.Service = "/" + service.ToLowerInvariant(); this.Template = template; this.Pattern = new UriPattern(template == "*" ? "/*" : template); var methodParams = method.GetParameters(); TotalParams = methodParams.Length; WithStream = TotalParams != 0 && methodParams[TotalParams - 1].ParameterType == typeof(Stream); var lamParams = new ParameterExpression[5]; lamParams[0] = Expression.Parameter(typeof(string[]), "strArr"); lamParams[1] = Expression.Parameter(typeof(IRequestContext), "request"); lamParams[2] = Expression.Parameter(typeof(IResponseContext), "response"); lamParams[3] = Expression.Parameter(typeof(Stream), "input"); lamParams[4] = Expression.Parameter(typeof(ChunkedMemoryStream), "output"); var expArgs = new Expression[TotalParams]; var argInd = 0; for (int i = 0; i < TotalParams; i++) { var mp = methodParams[i]; if (mp.ParameterType == typeof(IRequestContext)) { expArgs[i] = lamParams[1]; } else if (mp.ParameterType == typeof(IResponseContext)) { expArgs[i] = lamParams[2]; } else if (i < TotalParams - 1 || !WithStream) { expArgs[i] = Expression.ArrayIndex(lamParams[0], Expression.Constant(argInd++)); } else { expArgs[i] = lamParams[3]; } } var mce = Expression.Call(Expression.Constant(instance, instance.GetType()), method, expArgs); if (typeof(IHtmlView).IsAssignableFrom(method.ReturnType)) { mce = Expression.Call(null, RenderFunc.Method, mce, lamParams[2], lamParams[4]); } else if (!typeof(Stream).IsAssignableFrom(method.ReturnType) && method.ReturnType != typeof(void)) { var ws = Expression.Constant(serialization); mce = Expression.Call(null, SerializeFunc.Method, ws, lamParams[1], lamParams[2], mce, lamParams[4]); } var lambda = Expression.Lambda <Func <string[], IRequestContext, IResponseContext, Stream, ChunkedMemoryStream, Stream> >(mce, lamParams); Invocation = lambda.Compile(); }
public RouteHandler( string service, string template, object instance, bool isAsync, MethodInfo method, IServiceProvider locator, IWireSerialization serialization) { this.Service = "/" + service.ToLowerInvariant(); this.Template = template; this.Pattern = new UriPattern(template == "*" ? "/*" : template); this.IsAsync = isAsync; this.Url = Service + template; var methodParams = method.GetParameters(); TotalParams = methodParams.Length; WithStream = TotalParams != 0 && methodParams[TotalParams - 1].ParameterType == typeof(Stream); var lamParams = new ParameterExpression[5]; lamParams[0] = Expression.Parameter(typeof(string[]), "strArr"); lamParams[1] = Expression.Parameter(typeof(IRequestContext), "request"); lamParams[2] = Expression.Parameter(typeof(IResponseContext), "response"); lamParams[3] = Expression.Parameter(typeof(Stream), "input"); lamParams[4] = Expression.Parameter(typeof(ChunkedMemoryStream), "output"); var expArgs = new Expression[TotalParams]; var argInd = 0; for (int i = 0; i < TotalParams; i++) { var mp = methodParams[i]; if (mp.ParameterType == typeof(IRequestContext)) expArgs[i] = lamParams[1]; else if (mp.ParameterType == typeof(IResponseContext)) expArgs[i] = lamParams[2]; else if (i < TotalParams - 1 || !WithStream) expArgs[i] = Expression.ArrayIndex(lamParams[0], Expression.Constant(argInd++)); else expArgs[i] = lamParams[3]; } var mce = Expression.Call(Expression.Constant(instance, instance.GetType()), method, expArgs); if (typeof(IHtmlView).IsAssignableFrom(method.ReturnType)) { mce = Expression.Call(null, RenderFunc.Method, mce, lamParams[2], lamParams[4]); } else if (!typeof(Stream).IsAssignableFrom(method.ReturnType) && method.ReturnType != typeof(void)) { var ws = Expression.Constant(serialization); mce = Expression.Call(null, SerializeFunc.Method, ws, lamParams[1], lamParams[2], mce, lamParams[4]); } var lambda = Expression.Lambda<Func<string[], IRequestContext, IResponseContext, Stream, ChunkedMemoryStream, Stream>>(mce, lamParams); Invocation = lambda.Compile(); }
public RouteHandler(string service, string template, object instance, MethodInfo method) { this.Service = "/" + service.ToLowerInvariant(); this.Template = template; this.Pattern = new UriPattern(template == "*" ? "/*" : template); var methodParams = method.GetParameters(); TotalParams = methodParams.Length; WithStream = TotalParams != 0 && methodParams[TotalParams - 1].ParameterType == typeof(Stream); var lamParams = new ParameterExpression[2]; lamParams[0] = Expression.Parameter(typeof(string[]), "strArr"); lamParams[1] = Expression.Parameter(typeof(Stream), "input"); var expArgs = new Expression[TotalParams]; for (int i = 0; i < TotalParams; i++) { ArgumentOrder[methodParams[i].Name.ToUpperInvariant()] = i; if (i < TotalParams - 1 || !WithStream) expArgs[i] = Expression.ArrayIndex(lamParams[0], Expression.Constant(i)); else expArgs[i] = lamParams[1]; } var mce = Expression.Call(Expression.Constant(instance, instance.GetType()), method, expArgs); var lambda = Expression.Lambda<Func<string[], Stream, Stream>>(mce, lamParams); Invocation = lambda.Compile(); }