public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			var response = new GetWarmerResponse();
			var warmersByIndex = JObject.Load(reader).Properties().ToDictionary(p => p.Name, p => p.Value);
			if (!warmersByIndex.HasAny()) return response;
			response.Indices = new Dictionary<string, Warmers>();
			foreach (var warmerByIndex in warmersByIndex)
			{
				var index = warmerByIndex.Key;
				var warmersObject = JObject.FromObject(warmerByIndex.Value).Properties()
					.Where(p => p.Name == "warmers")
					.Select(p => p.Value)
					.FirstOrDefault();
				var warmers = new Warmers();
				if (warmersObject != null)
				{
					var warmersByName = JObject.FromObject(warmersObject).Properties()
						.ToDictionary(p => p.Name, p => p.Value);
					foreach (var warmerByName in warmersByName)
					{
						var name = warmerByName.Key;
						var warmer = warmerByName.Value.ToObject<Warmer>();
						warmers.Add(name, warmer);
					}
				}
				response.Indices.Add(warmerByIndex.Key, warmers);
			}
			return response;
		}
Exemplo n.º 2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var response       = new GetWarmerResponse();
            var warmersByIndex = JObject.Load(reader).Properties().ToDictionary(p => p.Name, p => p.Value);

            if (!warmersByIndex.HasAny())
            {
                return(response);
            }
            response.Indices = new Dictionary <string, Warmers>();
            foreach (var warmerByIndex in warmersByIndex)
            {
                var index         = warmerByIndex.Key;
                var warmersObject = JObject.FromObject(warmerByIndex.Value).Properties()
                                    .Where(p => p.Name == "warmers")
                                    .Select(p => p.Value)
                                    .FirstOrDefault();
                var warmers = new Warmers();
                if (warmersObject != null)
                {
                    var warmersByName = JObject.FromObject(warmersObject).Properties()
                                        .ToDictionary(p => p.Name, p => p.Value);
                    foreach (var warmerByName in warmersByName)
                    {
                        var name   = warmerByName.Key;
                        var warmer = warmerByName.Value.ToObject <Warmer>();
                        warmers.Add(name, warmer);
                    }
                }
                response.Indices.Add(warmerByIndex.Key, warmers);
            }
            return(response);
        }