Initialize the gmime for upstream
[platform/upstream/gmime.git] / mono / Multipart.custom
1 #region Native Methods
2                 [DllImport("gmime")]
3                 static extern int g_mime_multipart_get_count (IntPtr multipart);
4                 
5                 [DllImport("gmime")]
6                 static extern void g_mime_multipart_clear (IntPtr multipart);
7                 
8                 [DllImport("gmime")]
9                 static extern int g_mime_multipart_add (IntPtr multipart, IntPtr part);
10                 
11                 [DllImport("gmime")]
12                 static extern void g_mime_multipart_insert (IntPtr multipart, int index, IntPtr part);
13                 
14                 [DllImport("gmime")]
15                 static extern bool g_mime_multipart_remove (IntPtr multipart, IntPtr part);
16                 
17                 [DllImport("gmime")]
18                 static extern bool g_mime_multipart_remove_at (IntPtr multipart, int index);
19                 
20                 [DllImport("gmime")]
21                 static extern bool g_mime_multipart_contains (IntPtr multipart, IntPtr part);
22                 
23                 [DllImport("gmime")]
24                 static extern int g_mime_multipart_index_of (IntPtr multipart, IntPtr part);
25                 
26                 [DllImport("gmime")]
27                 static extern IntPtr g_mime_multipart_get_part (IntPtr multipart, int index);
28 #endregion
29                 
30                 Exception CannotAdd (object value)
31                 {
32                         if (value == null)
33                                 return new ArgumentNullException ("value");
34                         
35                         string message = String.Format ("Cannot add objects of type '{0}' to a GMime.Multipart.",
36                                                         value.GetType ().ToString ());
37                         
38                         return new InvalidOperationException (message);
39                 }
40                 
41                 Exception CannotInsert (object value)
42                 {
43                         if (value == null)
44                                 return new ArgumentNullException ("value");
45                         
46                         string message = String.Format ("Cannot insert objects of type '{0}' into a GMime.Multipart.",
47                                                         value.GetType ().ToString ());
48                         
49                         return new InvalidOperationException (message);
50                 }
51                 
52                 Exception CannotRemove (object value)
53                 {
54                         if (value == null)
55                                 return new ArgumentNullException ("value");
56                         
57                         string  message = String.Format ("Cannot remove objects of type '{0}' from a GMime.Multipart.",
58                                                          value.GetType ().ToString ());
59                         
60                         return new InvalidOperationException (message);
61                 }
62                 
63                 Exception CannotSet (object value)
64                 {
65                         if (value == null)
66                                 return new ArgumentNullException ("value");
67                         
68                         string message = String.Format ("Cannot set objects of type '{0}' on a GMime.Multipart.",
69                                                         value.GetType ().ToString ());
70                         
71                         return new InvalidOperationException (message);
72                 }
73                 
74                 public int Count { 
75                         get { return g_mime_multipart_get_count (Handle); }
76                 }
77                 
78                 public bool IsFixedSize {
79                         get { return false; }
80                 }
81                 
82                 public bool IsReadOnly {
83                         get { return false; }
84                 }
85                 
86                 public bool IsSynchronized {
87                         get { return false; }
88                 }
89                 
90                 public object SyncRoot {
91                         get { return this; }
92                 }
93                 
94                 public int Add (GMime.Entity part)
95                 {
96                         if (part == null)
97                                 throw CannotAdd (part);
98                         
99                         return g_mime_multipart_add (Handle, part.Handle);
100                 }
101                 
102                 int IList.Add (object value)
103                 {
104                         GMime.Entity part = value as GMime.Entity;
105                         
106                         if (part == null)
107                                 throw CannotAdd (value);
108                         
109                         return Add (part);
110                 }
111                 
112                 public void Clear ()
113                 {
114                         g_mime_multipart_clear (Handle);
115                 }
116                 
117                 public bool Contains (GMime.Entity part)
118                 {
119                         if (part == null)
120                                 return false;
121                         
122                         return g_mime_multipart_contains (Handle, part.Handle);
123                 }
124                 
125                 bool IList.Contains (object value)
126                 {
127                         return Contains (value as GMime.Entity);
128                 }
129                 
130                 public void CopyTo (Array array, int index)
131                 {
132                         if (array == null)
133                                 throw new ArgumentNullException ("array");
134                         
135                         if (index < 0)
136                                 throw new ArgumentOutOfRangeException ("index");
137                         
138                         int n = Count;
139                         
140                         for (int i = 0; i < n; i++)
141                                 array.SetValue (((IList) this)[i], index + i);
142                 }
143                 
144                 public IEnumerator GetEnumerator ()
145                 {
146                         int n = Count;
147                         
148                         for (int i = 0; i < n; i++)
149                                 yield return this[i];
150                         
151                         yield break;
152                 }
153                 
154                 public int IndexOf (GMime.Entity part)
155                 {
156                         if (part == null)
157                                 return -1;
158                         
159                         return g_mime_multipart_index_of (Handle, part.Handle);
160                 }
161                 
162                 int IList.IndexOf (object value)
163                 {
164                         return IndexOf (value as GMime.Entity);
165                 }
166                 
167                 public void Insert (int index, GMime.Entity part)
168                 {
169                         if (part == null)
170                                 throw CannotInsert (part);
171                         
172                         if (index < 0)
173                                 throw new ArgumentOutOfRangeException ("index");
174                         
175                         g_mime_multipart_insert (Handle, index, part.Handle);
176                 }
177                 
178                 void IList.Insert (int index, object value)
179                 {
180                         GMime.Entity part = value as GMime.Entity;
181                         
182                         if (part == null)
183                                 throw CannotInsert (value);
184                         
185                         Insert (index, part);
186                 }
187                 
188                 public void Remove (GMime.Entity part)
189                 {
190                         if (part == null)
191                                 throw CannotRemove (part);
192                         
193                         g_mime_multipart_remove (Handle, part.Handle);
194                 }
195                 
196                 void IList.Remove (object value)
197                 {
198                         GMime.Entity part = value as GMime.Entity;
199                         
200                         if (part == null)
201                                 throw CannotRemove (value);
202                         
203                         Remove (part);
204                 }
205                 
206                 public void RemoveAt (int index)
207                 {
208                         if (index < 0 || index >= Count)
209                                 throw new ArgumentOutOfRangeException ("index");
210                         
211                         g_mime_multipart_remove_at (Handle, index);
212                 }
213                 
214                 public GMime.Entity this[int index] {
215                         get {
216                                 IntPtr raw = g_mime_multipart_get_part (Handle, index);
217                                 
218                                 if (raw == IntPtr.Zero)
219                                         return null;
220                                 
221                                 return GLib.Object.GetObject (raw) as GMime.Entity;
222                         }
223                         
224                         set {
225                                 if (value == null)
226                                         throw CannotSet (value);
227                                 
228                                 if (index > Count || index < Count)
229                                         throw new ArgumentOutOfRangeException ("index");
230                                 
231                                 if (index < Count) {
232                                         RemoveAt (index);
233                                         Insert (index, value);
234                                 } else {
235                                         Add (value);
236                                 }
237                         }
238                 }
239                 
240                 object IList.this[int index] {
241                         get {
242                                 return this[index];
243                         }
244                         
245                         set {
246                                 this[index] = value as GMime.Entity;
247                         }
248                 }