internal static LastFmImage FromJson(JToken json) { if (json == null) { throw new ArgumentException("Json can not be null."); } var result = new LastFmImage(); var sizeToken = json.SelectToken("sizes.size"); if (sizeToken != null) { foreach (var size in sizeToken.Children()) { switch (size["name"].Value <string>()) { case "small": result.Small = size["#text"].Value <string>(); result.Width = Convert.ToDouble(size["width"].Value <string>()); result.Height = Convert.ToDouble(size["height"].Value <string>()); break; case "medium": result.Medium = size["#text"].Value <string>(); result.Width = Convert.ToDouble(size["width"].Value <string>()); result.Height = Convert.ToDouble(size["height"].Value <string>()); break; case "large": result.Large = size["#text"].Value <string>(); result.Width = Convert.ToDouble(size["width"].Value <string>()); result.Height = Convert.ToDouble(size["height"].Value <string>()); break; case "extralarge": result.ExtraLarge = size["#text"].Value <string>(); result.Width = Convert.ToDouble(size["width"].Value <string>()); result.Height = Convert.ToDouble(size["height"].Value <string>()); break; case "original": result.Original = size["#text"].Value <string>(); result.Width = Convert.ToDouble(size["width"].Value <string>()); result.Height = Convert.ToDouble(size["height"].Value <string>()); result.OriginalWidth = Convert.ToDouble(size["width"].Value <string>()); result.OriginalHeight = Convert.ToDouble(size["height"].Value <string>()); break; } } } return(result); }
internal static LastFmImage FromJson(JToken json) { if (json == null) throw new ArgumentException("Json can not be null."); var result = new LastFmImage(); var sizeToken = json.SelectToken("sizes.size"); if (sizeToken != null) { foreach (var size in sizeToken.Children()) { switch (size["name"].Value<string>()) { case "small": result.Small = size["#text"].Value<string>(); result.Width = Convert.ToDouble(size["width"].Value<string>()); result.Height = Convert.ToDouble(size["height"].Value<string>()); break; case "medium": result.Medium = size["#text"].Value<string>(); result.Width = Convert.ToDouble(size["width"].Value<string>()); result.Height = Convert.ToDouble(size["height"].Value<string>()); break; case "large": result.Large = size["#text"].Value<string>(); result.Width = Convert.ToDouble(size["width"].Value<string>()); result.Height = Convert.ToDouble(size["height"].Value<string>()); break; case "extralarge": result.ExtraLarge = size["#text"].Value<string>(); result.Width = Convert.ToDouble(size["width"].Value<string>()); result.Height = Convert.ToDouble(size["height"].Value<string>()); break; case "original": result.Original = size["#text"].Value<string>(); result.Width = Convert.ToDouble(size["width"].Value<string>()); result.Height = Convert.ToDouble(size["height"].Value<string>()); result.OriginalWidth = Convert.ToDouble(size["width"].Value<string>()); result.OriginalHeight = Convert.ToDouble(size["height"].Value<string>()); break; } } } return result; }