using System; using System.Xml.Serialization; using System.Xml.Schema; using System.Collections; namespace FlickrNet { /// [Serializable] public class Photos { /// [XmlElement("photo", Form=XmlSchemaForm.Unqualified)] public PhotoCollection PhotoCollection = new PhotoCollection(); /// [XmlAttribute("page", Form=XmlSchemaForm.Unqualified)] public long PageNumber; /// [XmlAttribute("pages", Form=XmlSchemaForm.Unqualified)] public long TotalPages; /// [XmlAttribute("perpage", Form=XmlSchemaForm.Unqualified)] public long PhotosPerPage; /// [XmlAttribute("total", Form=XmlSchemaForm.Unqualified)] public long TotalPhotos; } /// /// A collection of instances. /// [System.Serializable] public class PhotoCollection : CollectionBase { /// /// Default constructor. /// public PhotoCollection() { } /// /// Creates an instance of the from an array of /// instances. /// /// An array of instances. public PhotoCollection(Photo[] photos) { for (int i=0; i /// Gets number of photos in the current collection. /// public int Length { get { return List.Count; } } /// /// Gets the index of a photo in this collection. /// /// The photo to find. /// The index of the photo, -1 if it is not in the collection. public int IndexOf(Photo photo) { return List.IndexOf(photo); } #region ICollection Members /// /// Gets a value indicating if the collection is synchronized (thread-safe). /// public bool IsSynchronized { get { return List.IsSynchronized; } } /// /// Copies the elements of the collection to an array of , starting at a /// particular index. /// /// The array to copy to. /// The index in the collection to start copying from. public void CopyTo(Photo[] array, int index) { List.CopyTo(array, index); } /// /// Gets an object that can be used to synchronize the collection. /// public object SyncRoot { get { return List.SyncRoot; } } #endregion #region IList Members /// /// Gets a value indicating whether the collection is read-only. /// public bool IsReadOnly { get { return List.IsReadOnly; } } /// /// Gets or sets a photo based on the index in the collection. /// public Photo this[int index] { get { return (Photo)List[index]; } set { List[index] = value; } } /// /// Inserts a into the collection at the given index. /// /// The index to insert the into. /// Subsequent photos will be moved up. /// The to insert. public void Insert(int index, Photo photo) { List.Insert(index, photo); } /// /// Removes a photo from the collection. /// /// The instance to remove from the collection. public void Remove(Photo photo) { List.Remove(photo); } /// /// Returns true if the collection contains the photo. /// /// The instance to try to find. /// True of False, depending on if the is found in the collection. public bool Contains(Photo photo) { return List.Contains(photo); } /// /// Adds a to the collection. /// /// The instance to add to the collection. /// The index that the photo was added at. public int Add(Photo photo) { return List.Add(photo); } /// /// Adds an array of instances to this collection. /// /// An array of instances. public void AddRange(Photo[] photos) { foreach(Photo photo in photos) List.Add(photo); } /// /// Adds all of the photos in another to this collection. /// /// The containing the photos to add /// to this collection. public void AddRange(PhotoCollection collection) { foreach(Photo photo in collection) List.Add(photo); } /// /// Gets an instance specifying whether the collection is a fixed size. /// public bool IsFixedSize { get { return List.IsFixedSize; } } #endregion /// /// Converts a PhotoCollection instance to an array of Photo objects. /// /// The collection to convert. /// An array of objects. public static implicit operator Photo[](PhotoCollection collection) { Photo[] photos = new Photo[collection.Count]; collection.CopyTo(photos, 0); return photos; } /// /// Converts the collection to an array of objects. /// /// An array of objects. public Photo[] ToPhotoArray() { return (Photo[])this; } /// /// Implicitly converts an array of objects to a . /// /// The array of objects to convert. /// public static implicit operator PhotoCollection(Photo[] photos) { return new PhotoCollection(photos); } /// /// Creates a from an array of objects. /// /// An array of objects. /// A new containing all the objects from the array. public static PhotoCollection FromPhotoArray(Photo[] photos) { return (PhotoCollection)photos; } } }