using System; using System.Collections; using System.Collections.Generic; using Newtonsoft.Json.Linq; namespace IF.Lastfm.Core.Objects { public class LastImageCollection : IEnumerable { public Uri Small { get; set; } public Uri Medium { get; set; } public Uri Large { get; set; } public Uri ExtraLarge { get; set; } public Uri Mega { get; set; } private IEnumerable Images { get { return new List() { Small, Medium, Large, ExtraLarge, Mega }; } } public static LastImageCollection ParseJToken(JToken images) { var c = new LastImageCollection(); foreach (var image in images.Children()) { var size = image.Value("size"); var uriString = image.Value("#text"); if (string.IsNullOrEmpty(uriString)) { break; } var uri = new Uri(uriString, UriKind.Absolute); switch (size) { case "small": c.Small = uri; break; case "medium": c.Medium = uri; break; case "large": c.Large = uri; break; case "extralarge": c.ExtraLarge = uri; break; case "mega": c.Mega = uri; break; } } return c; } public IEnumerator GetEnumerator() { return Images.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } }