PageRenderTime 25ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/util/AssemblyList.cs

#
C# | 79 lines | 59 code | 10 blank | 10 comment | 7 complexity | 3e6b7728b5a3b971645fd9cfef827d51 MD5 | raw file
Possible License(s): GPL-2.0
  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. using System;
  7. using System.IO;
  8. using System.Collections;
  9. namespace NUnit.Util
  10. {
  11. /// <summary>
  12. /// Represents a list of assemblies. It stores paths
  13. /// that are added and fires an event whenevever it
  14. /// changes. All paths must be added as absolute paths.
  15. /// </summary>
  16. public class AssemblyList : CollectionBase
  17. {
  18. #region Properties and Events
  19. public string this[int index]
  20. {
  21. get { return (string)List[index]; }
  22. set
  23. {
  24. if ( !Path.IsPathRooted( value ) )
  25. throw new ArgumentException( "Assembly path must be absolute" );
  26. List[index] = value;
  27. }
  28. }
  29. public event EventHandler Changed;
  30. #endregion
  31. #region Methods
  32. public string[] ToArray()
  33. {
  34. return (string[])InnerList.ToArray( typeof( string ) );
  35. }
  36. public void Add( string assemblyPath )
  37. {
  38. if ( !Path.IsPathRooted( assemblyPath ) )
  39. throw new ArgumentException( "Assembly path must be absolute" );
  40. List.Add( assemblyPath );
  41. }
  42. public void Remove( string assemblyPath )
  43. {
  44. for( int index = 0; index < this.Count; index++ )
  45. {
  46. if ( this[index] == assemblyPath )
  47. RemoveAt( index );
  48. }
  49. }
  50. protected override void OnRemoveComplete(int index, object value)
  51. {
  52. FireChangedEvent();
  53. }
  54. protected override void OnInsertComplete(int index, object value)
  55. {
  56. FireChangedEvent();
  57. }
  58. protected override void OnSetComplete(int index, object oldValue, object newValue)
  59. {
  60. FireChangedEvent();
  61. }
  62. private void FireChangedEvent()
  63. {
  64. if ( Changed != null )
  65. Changed( this, EventArgs.Empty );
  66. }
  67. #endregion
  68. }
  69. }