PageRenderTime 34ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/util/ProjectConfigCollection.cs

#
C# | 105 lines | 83 code | 14 blank | 8 comment | 12 complexity | 4d32edda1c37e94ed8e217081a5fa137 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.Collections;
  8. namespace NUnit.Util
  9. {
  10. /// <summary>
  11. /// Summary description for ProjectConfigCollection.
  12. /// </summary>
  13. public class ProjectConfigCollection : CollectionBase
  14. {
  15. protected NUnitProject project;
  16. public ProjectConfigCollection( NUnitProject project )
  17. {
  18. this.project = project;
  19. }
  20. #region Properties
  21. public ProjectConfig this[int index]
  22. {
  23. get { return (ProjectConfig)InnerList[index]; }
  24. }
  25. public ProjectConfig this[string name]
  26. {
  27. get
  28. {
  29. int index = IndexOf( name );
  30. return index >= 0 ? (ProjectConfig)InnerList[index]: null;
  31. }
  32. }
  33. #endregion
  34. #region Methods
  35. public void Add( ProjectConfig config )
  36. {
  37. List.Add( config );
  38. config.Project = this.project;
  39. }
  40. public void Add( string name )
  41. {
  42. Add( new ProjectConfig( name ) );
  43. }
  44. public void Remove( string name )
  45. {
  46. int index = IndexOf( name );
  47. if ( index >= 0 )
  48. {
  49. RemoveAt( index );
  50. }
  51. }
  52. private int IndexOf( string name )
  53. {
  54. for( int index = 0; index < InnerList.Count; index++ )
  55. {
  56. ProjectConfig config = (ProjectConfig)InnerList[index];
  57. if( config.Name == name )
  58. return index;
  59. }
  60. return -1;
  61. }
  62. public bool Contains( ProjectConfig config )
  63. {
  64. return InnerList.Contains( config );
  65. }
  66. public bool Contains( string name )
  67. {
  68. return IndexOf( name ) >= 0;
  69. }
  70. protected override void OnRemove(int index, object value)
  71. {
  72. if (project != null)
  73. {
  74. ProjectConfig config = value as ProjectConfig;
  75. project.IsDirty = true;
  76. if ( config.Name == project.ActiveConfigName )
  77. project.HasChangesRequiringReload = true;
  78. }
  79. }
  80. protected override void OnInsertComplete( int index, object obj )
  81. {
  82. if (project != null)
  83. {
  84. project.IsDirty = true;
  85. if (this.Count == 1)
  86. project.HasChangesRequiringReload = true;
  87. }
  88. }
  89. #endregion
  90. }
  91. }