summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.UITest.TestCloud/Mono.Options/OptionValueCollection.cs
blob: 6ed604830ec3929120d8741ce7aac455c4b21f5a (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using System;
using System.Collections;
using System.Collections.Generic;

namespace Mono.Options
{
	public class OptionValueCollection : IList, IList<string>
	{
		readonly OptionContext _c;
		readonly List<string> _values = new List<string>();

		internal OptionValueCollection(OptionContext c)
		{
			_c = c;
		}

		#region IEnumerable

		IEnumerator IEnumerable.GetEnumerator()
		{
			return _values.GetEnumerator();
		}

		#endregion

		#region IEnumerable<T>

		public IEnumerator<string> GetEnumerator()
		{
			return _values.GetEnumerator();
		}

		#endregion

		public List<string> ToList()
		{
			return new List<string>(_values);
		}

		public string[] ToArray()
		{
			return _values.ToArray();
		}

		public override string ToString()
		{
			return string.Join(", ", _values.ToArray());
		}

		#region ICollection

		void ICollection.CopyTo(Array array, int index)
		{
			(_values as ICollection).CopyTo(array, index);
		}

		bool ICollection.IsSynchronized => (_values as ICollection).IsSynchronized;

		object ICollection.SyncRoot => (_values as ICollection).SyncRoot;

		#endregion

		#region ICollection<T>

		public void Add(string item)
		{
			_values.Add(item);
		}

		public void Clear()
		{
			_values.Clear();
		}

		public bool Contains(string item)
		{
			return _values.Contains(item);
		}

		public void CopyTo(string[] array, int arrayIndex)
		{
			_values.CopyTo(array, arrayIndex);
		}

		public bool Remove(string item)
		{
			return _values.Remove(item);
		}

		public int Count => _values.Count;

		public bool IsReadOnly => false;

		#endregion

		#region IList

		int IList.Add(object value)
		{
			return (_values as IList).Add(value);
		}

		bool IList.Contains(object value)
		{
			return (_values as IList).Contains(value);
		}

		int IList.IndexOf(object value)
		{
			return (_values as IList).IndexOf(value);
		}

		void IList.Insert(int index, object value)
		{
			(_values as IList).Insert(index, value);
		}

		void IList.Remove(object value)
		{
			(_values as IList).Remove(value);
		}

		void IList.RemoveAt(int index)
		{
			(_values as IList).RemoveAt(index);
		}

		bool IList.IsFixedSize => false;

		object IList.this[int index]
		{
			get { return this[index]; }
			set { (_values as IList)[index] = value; }
		}

		#endregion

		#region IList<T>

		public int IndexOf(string item)
		{
			return _values.IndexOf(item);
		}

		public void Insert(int index, string item)
		{
			_values.Insert(index, item);
		}

		public void RemoveAt(int index)
		{
			_values.RemoveAt(index);
		}

		void AssertValid(int index)
		{
			if (_c.Option == null)
				throw new InvalidOperationException("OptionContext.Option is null.");
			if (index >= _c.Option.MaxValueCount)
				throw new ArgumentOutOfRangeException("index");
			if (_c.Option.OptionValueType == OptionValueType.Required &&
			    index >= _values.Count)
			{
				throw new OptionException(string.Format(
					_c.OptionSet.MessageLocalizer("Missing required value for option '{0}'."), _c.OptionName),
					_c.OptionName);
			}
		}

		public string this[int index]
		{
			get
			{
				AssertValid(index);
				return index >= _values.Count ? null : _values[index];
			}
			set { _values[index] = value; }
		}

		#endregion
	}
}