File: ProjectConfigCollection.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (103 lines) | stat: -rw-r--r-- 2,381 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// ****************************************************************
// This is free software licensed under the NUnit license. You
// may obtain a copy of the license as well as information regarding
// copyright ownership at http://nunit.org/?p=license&r=2.4.
// ****************************************************************

using System;
using System.Collections;

namespace NUnit.Util
{
	/// <summary>
	/// Summary description for ProjectConfigCollection.
	/// </summary>
	public class ProjectConfigCollection : CollectionBase
	{
		protected NUnitProject project;

		public ProjectConfigCollection( NUnitProject project ) 
		{ 
			this.project = project;
		}

		#region Properties
		public ProjectConfig this[int index]
		{
			get { return (ProjectConfig)InnerList[index]; }
		}

		public ProjectConfig this[string name]
		{
			get 
			{ 
				int index = IndexOf( name );
				return index >= 0 ? (ProjectConfig)InnerList[index]: null;
			}
		}
		#endregion

		#region Methods
		public void Add( ProjectConfig config )
		{
			List.Add( config );
			config.Project = this.project;
			config.Changed += new EventHandler(config_Changed);
		}

		public void Add( string name )
		{
			Add( new ProjectConfig( name ) );
		}

		public void Remove( string name )
		{
			int index = IndexOf( name );
			if ( index >= 0 )
			{
				RemoveAt( index );
			}
		}

		private int IndexOf( string name )
		{
			for( int index = 0; index < InnerList.Count; index++ )
			{
				ProjectConfig config = (ProjectConfig)InnerList[index];
				if( config.Name == name )
					return index;
			}

			return -1;
		}

		public bool Contains( ProjectConfig config )
		{
			return InnerList.Contains( config );
		}

		public bool Contains( string name )
		{
			return IndexOf( name ) >= 0;
		}

		protected override void OnRemoveComplete( int index, object obj )
		{
			ProjectConfig config = obj as ProjectConfig;
			this.project.OnProjectChange( ProjectChangeType.RemoveConfig, config.Name );
		}

		protected override void OnInsertComplete( int index, object obj )
		{
			ProjectConfig config = obj as ProjectConfig;
			project.OnProjectChange( ProjectChangeType.AddConfig, config.Name );
		}

		private void config_Changed(object sender, EventArgs e)
		{
			ProjectConfig config = sender as ProjectConfig;
			project.OnProjectChange( ProjectChangeType.UpdateConfig, config.Name );
		}
		#endregion
	}
}