public void SetProperties(HttpResponseHeaders headers) { var properties = this.GetType().GetTypeInfo().DeclaredProperties; foreach (var prop in properties.Where(prop => headers.Any(h => h.Key == prop.Name))) { var value = headers.First(h => NetNamingMapper.GetPropertyName(h.Key) == prop.Name).Value; if(value == null) continue; if (value.Count() == 1) { prop.SetValue(this, value.FirstOrDefault()); } else { try { prop.SetValue(this, value.FirstOrDefault()); } catch (Exception) { // do nothing } } } }
public void SetProperties(HttpResponseHeaders headers) { var properties = this.GetType().GetProperties().Where(p => p.GetValue(this) != null); foreach (var prop in properties.Where(prop => headers.Any(h => h.Key == prop.Name))) { prop.SetValue(this, headers.First(h => NetNamingMapper.GetPropertyName(h.Key) == prop.Name)); } }
public static PagingInfo FindAndParsePagingInfo(HttpResponseHeaders responseHeaders) { // find the "X-Pagination" info in header if (responseHeaders.Contains("X-Pagination")) { var xPag = responseHeaders.First(ph => ph.Key == "X-Pagination").Value; // parse the value - this is a JSON-string. return JsonConvert.DeserializeObject<PagingInfo>(xPag.First()); } return null; }
public static PaginationInfo FindAndParsePaginationInfo(HttpResponseHeaders responseHeaders) { //find x-pagination if (responseHeaders.Contains("X-Pagination")) { var xPag = responseHeaders.First(rh => rh.Key == "X-Pagination").Value; return JsonConvert.DeserializeObject<PaginationInfo>(xPag.First()); } return null; }