public static async Task <object[]> ParseParams <T>(MappingInfo <T> mappingInfo, HttpListenerContext context) where T : IAbstractMapping { string path = context.Request.Url.AbsolutePath; return(await Task.Run(async() => { object[] methodParams = new object[mappingInfo.Method.GetParameters().Length]; var pathParamMatches = mappingInfo.Mapping.PathRegex.Match(path); if (pathParamMatches.Groups.Count > 1) { for (int i = 1; i < pathParamMatches.Groups.Count; i++) { int pathParamIndex = i - 1; var m = pathParamMatches.Groups[i]; foreach (var paramInfo in mappingInfo.RequiredParams.Values) { if (paramInfo.ParamPathIndex == pathParamIndex) { var converted = Convert.ChangeType(m.Value, paramInfo.ParamType); methodParams[paramInfo.ParamMethodIndex] = converted; } } } } if (mappingInfo.RequiredRequestBody != null) { object result; using (var reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding)) { var resultString = await reader.ReadToEndAsync(); var settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; settings.Formatting = Formatting.None; settings.MaxDepth = 15; result = JsonConvert.DeserializeObject(resultString, mappingInfo.RequiredRequestBody.Value.ParamType, settings); } methodParams[mappingInfo.RequiredRequestBody.Value.ParamMethodIndex] = result; } var injectionParams = InjectedAttribute.FindParameters(mappingInfo.Method, context); foreach (var injection in injectionParams) { methodParams[injection.ParameterPosition] = injection.ParameterObject; } return methodParams; })); }
private static IInjectedFacet Create(InjectedAttribute attribute, ISpecification holder) { return(attribute != null ? new InjectedFacet(holder) : null); }