PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/util/ProjectConfigCollection.cs

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