summaryrefslogtreecommitdiff
path: root/mono/Multipart.custom
blob: aef29ecd42cf6df3e93f05c6e9631df13634a732 (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#region Native Methods
		[DllImport("gmime")]
		static extern int g_mime_multipart_get_count (IntPtr multipart);
		
		[DllImport("gmime")]
		static extern void g_mime_multipart_clear (IntPtr multipart);
		
		[DllImport("gmime")]
		static extern int g_mime_multipart_add (IntPtr multipart, IntPtr part);
		
		[DllImport("gmime")]
		static extern void g_mime_multipart_insert (IntPtr multipart, int index, IntPtr part);
		
		[DllImport("gmime")]
		static extern bool g_mime_multipart_remove (IntPtr multipart, IntPtr part);
		
		[DllImport("gmime")]
		static extern bool g_mime_multipart_remove_at (IntPtr multipart, int index);
		
		[DllImport("gmime")]
		static extern bool g_mime_multipart_contains (IntPtr multipart, IntPtr part);
		
		[DllImport("gmime")]
		static extern int g_mime_multipart_index_of (IntPtr multipart, IntPtr part);
		
		[DllImport("gmime")]
		static extern IntPtr g_mime_multipart_get_part (IntPtr multipart, int index);
#endregion
		
		Exception CannotAdd (object value)
		{
			if (value == null)
				return new ArgumentNullException ("value");
			
			string message = String.Format ("Cannot add objects of type '{0}' to a GMime.Multipart.",
							value.GetType ().ToString ());
			
			return new InvalidOperationException (message);
		}
		
		Exception CannotInsert (object value)
		{
			if (value == null)
				return new ArgumentNullException ("value");
			
			string message = String.Format ("Cannot insert objects of type '{0}' into a GMime.Multipart.",
							value.GetType ().ToString ());
			
			return new InvalidOperationException (message);
		}
		
		Exception CannotRemove (object value)
		{
			if (value == null)
				return new ArgumentNullException ("value");
			
			string  message = String.Format ("Cannot remove objects of type '{0}' from a GMime.Multipart.",
							 value.GetType ().ToString ());
			
			return new InvalidOperationException (message);
		}
		
		Exception CannotSet (object value)
		{
			if (value == null)
				return new ArgumentNullException ("value");
			
			string message = String.Format ("Cannot set objects of type '{0}' on a GMime.Multipart.",
							value.GetType ().ToString ());
			
			return new InvalidOperationException (message);
		}
		
		public int Count { 
			get { return g_mime_multipart_get_count (Handle); }
		}
		
		public bool IsFixedSize {
			get { return false; }
		}
		
		public bool IsReadOnly {
			get { return false; }
		}
		
		public bool IsSynchronized {
			get { return false; }
		}
		
		public object SyncRoot {
			get { return this; }
		}
		
		public int Add (GMime.Entity part)
		{
			if (part == null)
				throw CannotAdd (part);
			
			return g_mime_multipart_add (Handle, part.Handle);
		}
		
		int IList.Add (object value)
		{
			GMime.Entity part = value as GMime.Entity;
			
			if (part == null)
				throw CannotAdd (value);
			
			return Add (part);
		}
		
		public void Clear ()
		{
			g_mime_multipart_clear (Handle);
		}
		
		public bool Contains (GMime.Entity part)
		{
			if (part == null)
				return false;
			
			return g_mime_multipart_contains (Handle, part.Handle);
		}
		
		bool IList.Contains (object value)
		{
			return Contains (value as GMime.Entity);
		}
		
		public void CopyTo (Array array, int index)
		{
			if (array == null)
				throw new ArgumentNullException ("array");
			
			if (index < 0)
				throw new ArgumentOutOfRangeException ("index");
			
			int n = Count;
			
			for (int i = 0; i < n; i++)
				array.SetValue (((IList) this)[i], index + i);
		}
		
		public IEnumerator GetEnumerator ()
		{
			int n = Count;
			
			for (int i = 0; i < n; i++)
				yield return this[i];
			
			yield break;
		}
		
		public int IndexOf (GMime.Entity part)
		{
			if (part == null)
				return -1;
			
			return g_mime_multipart_index_of (Handle, part.Handle);
		}
		
		int IList.IndexOf (object value)
		{
			return IndexOf (value as GMime.Entity);
		}
		
		public void Insert (int index, GMime.Entity part)
		{
			if (part == null)
				throw CannotInsert (part);
			
			if (index < 0)
				throw new ArgumentOutOfRangeException ("index");
			
			g_mime_multipart_insert (Handle, index, part.Handle);
		}
		
		void IList.Insert (int index, object value)
		{
			GMime.Entity part = value as GMime.Entity;
			
			if (part == null)
				throw CannotInsert (value);
			
			Insert (index, part);
		}
		
		public void Remove (GMime.Entity part)
		{
			if (part == null)
				throw CannotRemove (part);
			
			g_mime_multipart_remove (Handle, part.Handle);
		}
		
		void IList.Remove (object value)
		{
			GMime.Entity part = value as GMime.Entity;
			
			if (part == null)
				throw CannotRemove (value);
			
			Remove (part);
		}
		
		public void RemoveAt (int index)
		{
			if (index < 0 || index >= Count)
				throw new ArgumentOutOfRangeException ("index");
			
			g_mime_multipart_remove_at (Handle, index);
		}
		
		public GMime.Entity this[int index] {
			get {
				IntPtr raw = g_mime_multipart_get_part (Handle, index);
				
				if (raw == IntPtr.Zero)
					return null;
				
				return GLib.Object.GetObject (raw) as GMime.Entity;
			}
			
			set {
				if (value == null)
					throw CannotSet (value);
				
				if (index > Count || index < Count)
					throw new ArgumentOutOfRangeException ("index");
				
				if (index < Count) {
					RemoveAt (index);
					Insert (index, value);
				} else {
					Add (value);
				}
			}
		}
		
		object IList.this[int index] {
			get {
				return this[index];
			}
			
			set {
				this[index] = value as GMime.Entity;
			}
		}