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