diff options
Diffstat (limited to 'mono/SignatureCollection.custom')
-rw-r--r-- | mono/SignatureCollection.custom | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/mono/SignatureCollection.custom b/mono/SignatureCollection.custom new file mode 100644 index 0000000..332cadc --- /dev/null +++ b/mono/SignatureCollection.custom @@ -0,0 +1,243 @@ +#region Native Methods + [DllImport("gmime")] + static extern int g_mime_signature_list_length (IntPtr list); + + [DllImport("gmime")] + static extern void g_mime_signature_list_clear (IntPtr list); + + [DllImport("gmime")] + static extern int g_mime_signature_list_add (IntPtr list, IntPtr ia); + + [DllImport("gmime")] + static extern void g_mime_signature_list_insert (IntPtr list, int index, IntPtr ia); + + [DllImport("gmime")] + static extern bool g_mime_signature_list_remove (IntPtr list, IntPtr ia); + + [DllImport("gmime")] + static extern bool g_mime_signature_list_remove_at (IntPtr list, int index); + + [DllImport("gmime")] + static extern bool g_mime_signature_list_contains (IntPtr list, IntPtr ia); + + [DllImport("gmime")] + static extern int g_mime_signature_list_index_of (IntPtr list, IntPtr ia); + + [DllImport("gmime")] + static extern IntPtr g_mime_signature_list_get_signature (IntPtr list, int index); + + [DllImport("gmime")] + static extern void g_mime_signature_list_set_signature (IntPtr list, int index, IntPtr ia); +#endregion + + Exception CannotAdd (object value) + { + if (value == null) + return new ArgumentNullException ("value"); + + string message = String.Format ("Cannot add objects of type '{0}' to a SignatureCollection.", + 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 SignatureCollection.", + 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 SignatureCollection.", + 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 an SignatureCollection.", + value.GetType ().ToString ()); + + return new InvalidOperationException (message); + } + + public int Count { + get { return g_mime_signature_list_length (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 (Signature signature) + { + if (signature == null) + throw CannotAdd (signature); + + return g_mime_signature_list_add (Handle, signature.Handle); + } + + int IList.Add (object value) + { + Signature signature = value as Signature; + + if (signature == null) + throw CannotAdd (value); + + return Add (signature); + } + + public void Clear () + { + g_mime_signature_list_clear (Handle); + } + + public bool Contains (Signature signature) + { + if (signature == null) + return false; + + return g_mime_signature_list_contains (Handle, signature.Handle); + } + + bool IList.Contains (object value) + { + return Contains (value as Signature); + } + + 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 (Signature signature) + { + if (signature == null) + return -1; + + return g_mime_signature_list_index_of (Handle, signature.Handle); + } + + int IList.IndexOf (object value) + { + return IndexOf (value as Signature); + } + + public void Insert (int index, Signature signature) + { + if (signature == null) + throw CannotInsert (signature); + + if (index < 0) + throw new ArgumentOutOfRangeException ("index"); + + g_mime_signature_list_insert (Handle, index, signature.Handle); + } + + void IList.Insert (int index, object value) + { + Signature signature = value as Signature; + + if (signature == null) + throw CannotInsert (value); + + Insert (index, signature); + } + + public void Remove (Signature signature) + { + if (signature == null) + throw CannotRemove (signature); + + g_mime_signature_list_remove (Handle, signature.Handle); + } + + void IList.Remove (object value) + { + Signature signature = value as Signature; + + if (signature == null) + throw CannotRemove (value); + + Remove (signature); + } + + public void RemoveAt (int index) + { + if (index < 0 || index >= Count) + throw new ArgumentOutOfRangeException ("index"); + + g_mime_signature_list_remove_at (Handle, index); + } + + public Signature this[int index] { + get { + IntPtr raw = g_mime_signature_list_get_signature (Handle, index); + + if (raw == IntPtr.Zero) + return null; + + return GLib.Object.GetObject (raw) as Signature; + } + + set { + if (value == null) + throw CannotSet (value); + + g_mime_signature_list_set_signature (Handle, index, value.Handle); + } + } + + object IList.this[int index] { + get { + return this[index]; + } + + set { + this[index] = value as Signature; + } + } |