/// <summary> /// Copies the elements of the <see cref="TrackCollection"/> to a new /// <see cref="Array"/> of <see cref="Track"/> elements. /// </summary> /// <returns>A one-dimensional <see cref="Array"/> of <see cref="Track"/> /// elements containing copies of the elements of the <see cref="TrackCollection"/>.</returns> /// <remarks>Please refer to <see cref="ArrayList.ToArray"/> for details.</remarks> public virtual Track[] ToArray() { Track[] array = new Track[this._count]; Array.Copy(this._array, array, this._count); return array; }
/// <overloads> /// Copies the <see cref="TrackCollection"/> or a portion of it to a one-dimensional array. /// </overloads> /// <summary> /// Copies the entire <see cref="TrackCollection"/> to a one-dimensional <see cref="Array"/> /// of <see cref="Track"/> elements, starting at the beginning of the target array. /// </summary> /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the /// <see cref="Track"/> elements copied from the <see cref="TrackCollection"/>. /// The <b>Array</b> must have zero-based indexing.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="ArgumentException"> /// The number of elements in the source <see cref="TrackCollection"/> is greater /// than the available space in the destination <paramref name="array"/>.</exception> /// <remarks>Please refer to <see cref="ArrayList.CopyTo"/> for details.</remarks> public virtual void CopyTo(Track[] array) { CheckTargetArray(array, 0); Array.Copy(this._array, array, this._count); }
/// <summary> /// Create an instance of a Track passing in a track /// </summary> /// <param name="title"></param> public Track(Track src) { m_Title = src.m_Title; m_ExtendedData = src.m_ExtendedData; m_FrameOffset = src.m_FrameOffset; }
/// <summary> /// Adds a <see cref="Track"/> to the end of the <see cref="TrackCollection"/>. /// </summary> /// <param name="value">The <see cref="Track"/> object /// to be added to the end of the <see cref="TrackCollection"/>. /// This argument can be a null reference. /// </param> /// <returns>The <see cref="TrackCollection"/> index at which the /// <paramref name="value"/> has been added.</returns> /// <exception cref="NotSupportedException"> /// <para>The <see cref="TrackCollection"/> is read-only.</para> /// <para>-or-</para> /// <para>The <b>TrackCollection</b> has a fixed size.</para> /// <para>-or-</para> /// <para>The <b>TrackCollection</b> already contains the specified /// <paramref name="value"/>, and the <b>TrackCollection</b> /// ensures that all elements are unique.</para></exception> /// <remarks>Please refer to <see cref="ArrayList.Add"/> for details.</remarks> public virtual int Add(Track value) { if (this._count == this._array.Length) EnsureCapacity(this._count + 1); ++this._version; this._array[this._count] = value; return this._count++; }
/// <summary> /// Searches the entire sorted <see cref="TrackCollection"/> for an /// <see cref="Track"/> element using the default comparer /// and returns the zero-based index of the element. /// </summary> /// <param name="value">The <see cref="Track"/> object /// to locate in the <see cref="TrackCollection"/>. /// This argument can be a null reference. /// </param> /// <returns>The zero-based index of <paramref name="value"/> in the sorted /// <see cref="TrackCollection"/>, if <paramref name="value"/> is found; /// otherwise, a negative number, which is the bitwise complement of the index /// of the next element that is larger than <paramref name="value"/> or, if there /// is no larger element, the bitwise complement of <see cref="Count"/>.</returns> /// <exception cref="InvalidOperationException"> /// Neither <paramref name="value"/> nor the elements of the <see cref="TrackCollection"/> /// implement the <see cref="IComparable"/> interface.</exception> /// <remarks>Please refer to <see cref="ArrayList.BinarySearch"/> for details.</remarks> public virtual int BinarySearch(Track value) { return Array.BinarySearch(this._array, 0, this._count, value); }
public override void Remove(Track value) { this._collection.Remove(value); }
private void CheckUnique(int index, Track value) { int existing = IndexOf(value); if (existing >= 0 && existing != index) throw new NotSupportedException( "Unique collections cannot contain duplicate elements."); }
public override void CopyTo(Track[] array) { lock (this._root) this._collection.CopyTo(array); }
public override int IndexOf(Track value) { lock (this._root) return this._collection.IndexOf(value); }
public override int Add(Track value) { lock (this._root) return this._collection.Add(value); }
public override void AddRange(Track[] array) { lock (this._root) this._collection.AddRange(array); }
public override void Remove(Track value) { throw new NotSupportedException( "Read-only collections cannot be modified."); }
public override void Insert(int index, Track value) { throw new NotSupportedException( "Read-only collections cannot be modified."); }
public override void AddRange(Track[] array) { throw new NotSupportedException( "Read-only collections cannot be modified."); }
public override int IndexOf(Track value) { return this._collection.IndexOf(value); }
public override void Insert(int index, Track value) { lock (this._root) this._collection.Insert(index, value); }
public override void Insert(int index, Track value) { CheckUnique(value); this._collection.Insert(index, value); }
public override void Remove(Track value) { lock (this._root) this._collection.Remove(value); }
private void CheckUnique(Track value) { if (IndexOf(value) >= 0) throw new NotSupportedException( "Unique collections cannot contain duplicate elements."); }
public override int Add(Track value) { CheckUnique(value); return this._collection.Add(value); }
/// <summary> /// Initializes a new instance of the <see cref="TrackCollection"/> class /// that contains elements copied from the specified <see cref="Track"/> /// array and that has the same initial capacity as the number of elements copied. /// </summary> /// <param name="array">An <see cref="Array"/> of <see cref="Track"/> /// elements that are copied to the new collection.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <remarks>Please refer to <see cref="ArrayList(ICollection)"/> for details.</remarks> public TrackCollection(Track[] array) { if (array == null) throw new ArgumentNullException("array"); this._array = new Track[array.Length]; AddRange(array); }
public override void AddRange(Track[] array) { foreach (Track value in array) CheckUnique(value); this._collection.AddRange(array); }
/// <summary> /// Adds the elements of a <see cref="Track"/> array /// to the end of the <see cref="TrackCollection"/>. /// </summary> /// <param name="array">An <see cref="Array"/> of <see cref="Track"/> elements /// that should be added to the end of the <see cref="TrackCollection"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="NotSupportedException"> /// <para>The <see cref="TrackCollection"/> is read-only.</para> /// <para>-or-</para> /// <para>The <b>TrackCollection</b> has a fixed size.</para> /// <para>-or-</para> /// <para>The <b>TrackCollection</b> already contains one or more elements /// in the specified <paramref name="array"/>, and the <b>TrackCollection</b> /// ensures that all elements are unique.</para></exception> /// <remarks>Please refer to <see cref="ArrayList.AddRange"/> for details.</remarks> public virtual void AddRange(Track[] array) { if (array == null) throw new ArgumentNullException("array"); if (array.Length == 0) return; if (this._count + array.Length > this._array.Length) EnsureCapacity(this._count + array.Length); ++this._version; Array.Copy(array, 0, this._array, this._count, array.Length); this._count += array.Length; }
public override int BinarySearch(Track value) { return this._collection.BinarySearch(value); }
/// <summary> /// Determines whether the <see cref="TrackCollection"/> /// contains the specified <see cref="Track"/> element. /// </summary> /// <param name="value">The <see cref="Track"/> object /// to locate in the <see cref="TrackCollection"/>. /// This argument can be a null reference. /// </param> /// <returns><c>true</c> if <paramref name="value"/> is found in the /// <see cref="TrackCollection"/>; otherwise, <c>false</c>.</returns> /// <remarks>Please refer to <see cref="ArrayList.Contains"/> for details.</remarks> public bool Contains(Track value) { return (IndexOf(value) >= 0); }
public override void CopyTo(Track[] array) { this._collection.CopyTo(array); }
/// <summary> /// Copies the entire <see cref="TrackCollection"/> to a one-dimensional <see cref="Array"/> /// of <see cref="Track"/> elements, starting at the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the /// <see cref="Track"/> elements copied from the <see cref="TrackCollection"/>. /// The <b>Array</b> must have zero-based indexing.</param> /// <param name="arrayIndex">The zero-based index in <paramref name="array"/> /// at which copying begins.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="arrayIndex"/> is less than zero.</exception> /// <exception cref="ArgumentException"><para> /// <paramref name="arrayIndex"/> is equal to or greater than the length of <paramref name="array"/>. /// </para><para>-or-</para><para> /// The number of elements in the source <see cref="TrackCollection"/> is greater than the /// available space from <paramref name="arrayIndex"/> to the end of the destination /// <paramref name="array"/>.</para></exception> /// <remarks>Please refer to <see cref="ArrayList.CopyTo"/> for details.</remarks> public virtual void CopyTo(Track[] array, int arrayIndex) { CheckTargetArray(array, arrayIndex); Array.Copy(this._array, 0, array, arrayIndex, this._count); }
public override void CopyTo(Track[] array, int arrayIndex) { this._collection.CopyTo(array, arrayIndex); }
private bool Parse(StringCollection data) { foreach (string line in data) { // check for comment if (line[0] == '#') continue; int index = line.IndexOf('='); if (index == -1) // couldn't find equal sign have no clue what the data is continue; string field = line.Substring(0,index); index++; // move it past the equal sign switch (field) { case "DISCID": { this.m_Discid = line.Substring(index); continue; } case "DTITLE": // artist / title { this.m_Artist += line.Substring(index); continue; } case "DYEAR": { this.m_Year = line.Substring(index); continue; } case "DGENRE": { this.m_Genre += line.Substring(index); continue; } case "EXTD": { // may be more than one - just concatenate them this.m_ExtendedData += line.Substring(index); continue; } case "PLAYORDER": { this.m_PlayOrder += line.Substring(index); continue; } default: //get track info or extended track info if (field.StartsWith("TTITLE")) { int trackNumber = -1; // Parse could throw an exception try { trackNumber = int.Parse(field.Substring("TTITLE".Length)); } catch (Exception ex) { Debug.WriteLine("Failed to parse track Number. Reason: " + ex.Message); continue; } //may need to concatenate track info if (trackNumber < m_Tracks.Count ) m_Tracks[trackNumber].Title += line.Substring(index); else { Track track = new Track(line.Substring(index)); this.m_Tracks.Add(track); } continue; } else if (field.StartsWith("EXTT")) { int trackNumber = -1; // Parse could throw an exception try { trackNumber = int.Parse(field.Substring("EXTT".Length)); } catch (Exception ex) { Debug.WriteLine("Failed to parse track Number. Reason: " + ex.Message); continue; } if (trackNumber < 0 || trackNumber > m_Tracks.Count -1) continue; m_Tracks[trackNumber].ExtendedData += line.Substring(index); } continue; } //end of switch } //split the title and artist from DTITLE; // see if we have a slash int slash = this.m_Artist.IndexOf(" / "); if (slash == -1) { this.m_Title= m_Artist; } else { string titleArtist = m_Artist; this.m_Artist = titleArtist.Substring(0,slash); slash +=3; // move past " / " this.m_Title = titleArtist.Substring(slash ); } return true; }
/// <summary> /// Removes the first occurrence of the specified <see cref="Track"/> /// from the <see cref="TrackCollection"/>. /// </summary> /// <param name="value">The <see cref="Track"/> object /// to remove from the <see cref="TrackCollection"/>. /// This argument can be a null reference. /// </param> /// <exception cref="NotSupportedException"> /// <para>The <see cref="TrackCollection"/> is read-only.</para> /// <para>-or-</para> /// <para>The <b>TrackCollection</b> has a fixed size.</para></exception> /// <remarks>Please refer to <see cref="ArrayList.Remove"/> for details.</remarks> public virtual void Remove(Track value) { int index = IndexOf(value); if (index >= 0) RemoveAt(index); }