private static bool SetSpecialTypes <TResponse>(byte[] bytes, out TResponse cs) where TResponse : class, IElasticsearchResponse, new() { cs = null; var responseType = typeof(TResponse); if (!SpecialTypes.Contains(responseType)) { return(false); } if (responseType == typeof(StringResponse)) { cs = new StringResponse(bytes.Utf8String()) as TResponse; } else if (responseType == typeof(byte[])) { cs = new BytesResponse(bytes) as TResponse; } else if (responseType == typeof(VoidResponse)) { cs = StaticVoid as TResponse; } else if (responseType == typeof(DynamicResponse)) { using (var ms = new MemoryStream(bytes)) { var body = LowLevelRequestResponseSerializer.Instance.Deserialize <DynamicBody>(ms); cs = new DynamicResponse(body) as TResponse; } } return(cs != null); }
private static bool SetSpecialTypes <TResponse>(string mimeType, byte[] bytes, IMemoryStreamFactory memoryStreamFactory, out TResponse cs) where TResponse : class, IElasticsearchResponse, new() { cs = null; var responseType = typeof(TResponse); if (!SpecialTypes.Contains(responseType)) { return(false); } if (responseType == typeof(StringResponse)) { cs = new StringResponse(bytes.Utf8String()) as TResponse; } else if (responseType == typeof(BytesResponse)) { cs = new BytesResponse(bytes) as TResponse; } else if (responseType == typeof(VoidResponse)) { cs = new VoidResponse() as TResponse; } else if (responseType == typeof(DynamicResponse)) { //if not json store the result under "body" if (mimeType != RequestData.MimeType) { var dictionary = new DynamicDictionary(); dictionary["body"] = new DynamicValue(bytes.Utf8String()); cs = new DynamicResponse(dictionary) as TResponse; } else { using (var ms = memoryStreamFactory.Create(bytes)) { var body = LowLevelRequestResponseSerializer.Instance.Deserialize <DynamicDictionary>(ms); cs = new DynamicResponse(body) as TResponse; } } } return(cs != null); }