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
                    }
                }
            }
        }
Пример #2
0
        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));
            }
        }