/src/NUnit/util/AssemblyList.cs
C# | 79 lines | 59 code | 10 blank | 10 comment | 7 complexity | 3e6b7728b5a3b971645fd9cfef827d51 MD5 | raw file
1// **************************************************************** 2// This is free software licensed under the NUnit license. You 3// may obtain a copy of the license as well as information regarding 4// copyright ownership at http://nunit.org. 5// **************************************************************** 6 7using System; 8using System.IO; 9using System.Collections; 10 11namespace NUnit.Util 12{ 13 /// <summary> 14 /// Represents a list of assemblies. It stores paths 15 /// that are added and fires an event whenevever it 16 /// changes. All paths must be added as absolute paths. 17 /// </summary> 18 public class AssemblyList : CollectionBase 19 { 20 #region Properties and Events 21 public string this[int index] 22 { 23 get { return (string)List[index]; } 24 set 25 { 26 if ( !Path.IsPathRooted( value ) ) 27 throw new ArgumentException( "Assembly path must be absolute" ); 28 List[index] = value; 29 } 30 } 31 32 public event EventHandler Changed; 33 #endregion 34 35 #region Methods 36 public string[] ToArray() 37 { 38 return (string[])InnerList.ToArray( typeof( string ) ); 39 } 40 41 public void Add( string assemblyPath ) 42 { 43 if ( !Path.IsPathRooted( assemblyPath ) ) 44 throw new ArgumentException( "Assembly path must be absolute" ); 45 List.Add( assemblyPath ); 46 } 47 48 public void Remove( string assemblyPath ) 49 { 50 for( int index = 0; index < this.Count; index++ ) 51 { 52 if ( this[index] == assemblyPath ) 53 RemoveAt( index ); 54 } 55 } 56 57 protected override void OnRemoveComplete(int index, object value) 58 { 59 FireChangedEvent(); 60 } 61 62 protected override void OnInsertComplete(int index, object value) 63 { 64 FireChangedEvent(); 65 } 66 67 protected override void OnSetComplete(int index, object oldValue, object newValue) 68 { 69 FireChangedEvent(); 70 } 71 72 private void FireChangedEvent() 73 { 74 if ( Changed != null ) 75 Changed( this, EventArgs.Empty ); 76 } 77 #endregion 78 } 79}