[gmime] Updated .NET bindings



commit 21ef1c145d2be1d163e2e559dc26bbfc7dc368e7
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Wed Mar 16 22:53:02 2011 -0400

    Updated .NET bindings
    
    2011-03-16  Jeffrey Stedfast  <fejj novell com>
    
    	* mono/CryptoRecipientCollection.cs:
    	* mono/SignerCollection.cs: New collections for Signers and
    	CryptoRecipients.
    
    	* mono/SignatureValidity.custom:
    	* mono/DecryptionResult.custom: Don't return IEnumerators for
    	signers/recipients, return the appropriate Collections instead.

 ChangeLog                         |   10 ++++
 mono/CryptoRecipientCollection.cs |   84 +++++-------------------------------
 mono/DecryptionResult.custom      |   45 +-------------------
 mono/GMime.metadata               |    1 +
 mono/InternetAddressList.custom   |    2 +-
 mono/Makefile.am                  |   48 ++++++++++++---------
 mono/SignatureValidity.custom     |   45 +-------------------
 mono/SignerCollection.cs          |   83 +++++-------------------------------
 8 files changed, 67 insertions(+), 251 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bd0d55b..1889ff3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-03-16  Jeffrey Stedfast  <fejj novell com>
+
+	* mono/CryptoRecipientCollection.cs:
+	* mono/SignerCollection.cs: New collections for Signers and
+	CryptoRecipients.
+
+	* mono/SignatureValidity.custom:
+	* mono/DecryptionResult.custom: Don't return IEnumerators for
+	signers/recipients, return the appropriate Collections instead.
+
 2011-03-15  Jeffrey Stedfast  <fejj novell com>
 
 	* mono/SignatureValidity.custom: 
diff --git a/mono/CryptoRecipientCollection.cs b/mono/CryptoRecipientCollection.cs
index 7695925..790bb9e 100644
--- a/mono/CryptoRecipientCollection.cs
+++ b/mono/CryptoRecipientCollection.cs
@@ -4,30 +4,22 @@ using System.Runtime.InteropServices;
 
 namespace GMime {
 	public class CryptoRecipientCollection : IList {
-		CryptoRecipient[] recipients;
+		ArrayList recipients;
 		
 		internal CryptoRecipientCollection (DecryptionResult result)
 		{
 			CryptoRecipient recipient;
-			int count = 0;
-			int i = 0;
 			
+			recipients = new ArrayList ();
 			recipient = GetFirstRecipient (result);
 			while (recipient != null) {
-				recipient = recipient.Next ();
-				count++;
-			}
-			
-			recipients = new CryptoRecipient [count];
-			recipient = GetFirstRecipient (result);
-			while (recipient != null) {
-				recipients[i++] = recipient;
+				recipients.Add (recipient);
 				recipient = recipient.Next ();
 			}
 		}
 		
 		public int Count {
-			get { return recipients.Length; }
+			get { return recipients.Count; }
 		}
 		
 		public bool IsFixedSize {
@@ -58,55 +50,32 @@ namespace GMime {
 		
 		public bool Contains (CryptoRecipient recipient)
 		{
-			if (recipient == null)
-				return false;
-			
-			for (int i = 0; i < Count; i++) {
-				if (recipients[i] == recipient)
-					return true;
-			}
-			
-			return false;
+			return recipients.Contains (recipient);
 		}
 		
 		bool IList.Contains (object value)
 		{
-			return Contains (value as CryptoRecipient);
+			return recipients.Contains (value);
 		}
 		
 		public void CopyTo (Array array, int index)
 		{
-			if (array == null)
-				throw new ArgumentNullException ("array");
-			
-			if (index < 0)
-				throw new ArgumentOutOfRangeException ("index");
-			
-			for (int i = 0; i < Count; i++)
-				array.SetValue (((IList) this)[i], index + i);
+			recipients.CopyTo (array, index);
 		}
 		
 		public IEnumerator GetEnumerator ()
 		{
-			return new CryptoRecipientIterator (this);
+			return recipients.GetEnumerator ();
 		}
 		
 		public int IndexOf (CryptoRecipient recipient)
 		{
-			if (recipient == null)
-				return -1;
-			
-			for (int i = 0; i < Count; i++) {
-				if (recipients[i] == recipient)
-					return i;
-			}
-			
-			return -1;
+			return recipients.IndexOf (recipient);
 		}
 		
 		int IList.IndexOf (object value)
 		{
-			return IndexOf (value as CryptoRecipient);
+			return recipients.IndexOf (value);
 		}
 		
 		void IList.Insert (int index, object value)
@@ -126,10 +95,7 @@ namespace GMime {
 		
 		public CryptoRecipient this[int index] {
 			get {
-				if (index > Count)
-					throw new ArgumentOutOfRangeException ("index");
-				
-				return recipients[index];
+				return recipients[index] as CryptoRecipient;
 			}
 			
 			set {
@@ -139,7 +105,7 @@ namespace GMime {
 		
 		object IList.this[int index] {
 			get {
-				return this[index];
+				return recipients[index];
 			}
 			
 			set {
@@ -159,31 +125,5 @@ namespace GMime {
 			
 			return (CryptoRecipient) GLib.Opaque.GetOpaque (rv, typeof (CryptoRecipient), false);
 		}
-		
-		internal class CryptoRecipientIterator : IEnumerator {
-			CryptoRecipientCollection recipients;
-			int index = -1;
-			
-			public CryptoRecipientIterator (CryptoRecipientCollection recipients)
-			{
-				this.recipients = recipients;
-			}
-			
-			public object Current {
-				get { return index >= 0 ? recipients[index] : null; }
-			}
-			
-			public void Reset ()
-			{
-				index = -1;
-			}
-			
-			public bool MoveNext ()
-			{
-				index++;
-				
-				return index < recipients.Count;
-			}
-		}
 	}
 }
diff --git a/mono/DecryptionResult.custom b/mono/DecryptionResult.custom
index aedf9c7..7726051 100644
--- a/mono/DecryptionResult.custom
+++ b/mono/DecryptionResult.custom
@@ -1,44 +1,3 @@
-		[DllImport("gmime")]
-		static extern IntPtr g_mime_decryption_result_get_recipients(IntPtr raw);
-
-		public IEnumerator Recipients {
-			get { return new GMimeCryptoRecipientIterator (this); }
-		}
-
-		internal class GMimeCryptoRecipientIterator : IEnumerator {
-			GMime.CryptoRecipient recipient;
-			GMime.DecryptionResult result;
-			int index = -1;
-
-			public GMimeCryptoRecipientIterator (GMime.DecryptionResult result)
-			{
-				this.result = result;
-			}
-			
-			public object Current {
-				get { return recipient; }
-			}
-			
-			public void Reset ()
-			{
-				recipient = null;
-				index = -1;
-			}
-			
-			public bool MoveNext ()
-			{
-				IntPtr rv;
-				
-				if (index == -1) {
-					rv = g_mime_decryption_result_get_recipients (result.Handle);
-					if (rv != IntPtr.Zero)
-						recipient = (GMime.CryptoRecipient) GLib.Opaque.GetOpaque (rv, typeof (GMime.CryptoRecipient), false);
-				} else {
-					recipient = recipient.Next ();
-				}
-				
-				index++;
-				
-				return recipient != null;
-			}
+		public CryptoRecipientCollection Recipients {
+			get { return new CryptoRecipientCollection (this); }
 		}
diff --git a/mono/GMime.metadata b/mono/GMime.metadata
index a22116e..3ec91e5 100644
--- a/mono/GMime.metadata
+++ b/mono/GMime.metadata
@@ -49,6 +49,7 @@
 
   <!-- CryptoContext -->
   <remove-node path="/api/namespace/struct[ cname='GMimeDecryptionResult']/method[ name='GetRecipients']"/>
+  <remove-node path="/api/namespace/struct[ cname='GMimeDecryptionResult']/method[ name='AddRecipient']"/>
   <remove-node path="/api/namespace/struct[ cname='GMimeDecryptionResult']/field[ cname='recipients']"/>
   <remove-node path="/api/namespace/struct[ cname='GMimeSignatureValidity']/method[ name='GetSigners']"/>
   <remove-node path="/api/namespace/struct[ cname='GMimeSignatureValidity']/method[ name='AddSigner']"/>
diff --git a/mono/InternetAddressList.custom b/mono/InternetAddressList.custom
index a5f7bda..2563bdd 100644
--- a/mono/InternetAddressList.custom
+++ b/mono/InternetAddressList.custom
@@ -83,7 +83,7 @@
 			return new InvalidOperationException (message);
 		}
 		
-		public int Count { 
+		public int Count {
 			get { return internet_address_list_length (Handle); }
 		}
 		
diff --git a/mono/Makefile.am b/mono/Makefile.am
index 349aa51..c2c4077 100644
--- a/mono/Makefile.am
+++ b/mono/Makefile.am
@@ -15,22 +15,27 @@ DISTCLEANFILES = $(ASSEMBLY).config AssemblyInfo.cs gmime-sharp-$(GMIME_API_VERS
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = $(PACKAGE_SHARP).pc
 
-sources = 				\
+sources = 					\
+	CryptoRecipientCollection.cs		\
+	SignerCollection.cs			\
 	StreamWrapper.cs
 
-build_sources =  			\
-	$(srcdir)/StreamWrapper.cs	\
+build_sources =  				\
+	$(srcdir)/CryptoRecipientCollection.cs	\
+	$(srcdir)/SignerCollection.cs		\
+	$(srcdir)/StreamWrapper.cs		\
 	AssemblyInfo.cs
 
-customs = 				\
-	DataWrapper.custom		\
-	Global.custom			\
-	HeaderList.custom		\
-	InternetAddress.custom		\
-	InternetAddressList.custom	\
-	Message.custom			\
-	Multipart.custom		\
-	Object.custom			\
+customs = 					\
+	DataWrapper.custom			\
+	Global.custom				\
+	HeaderList.custom			\
+	InternetAddress.custom			\
+	InternetAddressList.custom		\
+	Message.custom				\
+	Multipart.custom			\
+	Object.custom				\
+	SignatureValididty.custom		\
 	Stream.custom
 
 build_customs = 				\
@@ -42,17 +47,18 @@ build_customs = 				\
 	$(srcdir)/Message.custom		\
 	$(srcdir)/Multipart.custom		\
 	$(srcdir)/Object.custom			\
+	$(srcdir)/SignatureValidity.custom	\
 	$(srcdir)/Stream.custom
 
-EXTRA_DIST =			\
-	$(ASSEMBLY).config.in	\
-	$(ASSEMBLY_NAME).snk	\
-	AssemblyInfo.cs.in	\
-	$(METADATA)		\
-	$(RAW_API)		\
-	$(customs)		\
-	$(sources)		\
-	$(SOURCES_XML)		\
+EXTRA_DIST =					\
+	$(ASSEMBLY).config.in			\
+	$(ASSEMBLY_NAME).snk			\
+	AssemblyInfo.cs.in			\
+	$(METADATA)				\
+	$(RAW_API)				\
+	$(customs)				\
+	$(sources)				\
+	$(SOURCES_XML)				\
 	gmime-sharp.pc.in
 
 $(PACKAGE_SHARP).pc: gmime-sharp.pc
diff --git a/mono/SignatureValidity.custom b/mono/SignatureValidity.custom
index 59b02f8..5df017f 100644
--- a/mono/SignatureValidity.custom
+++ b/mono/SignatureValidity.custom
@@ -1,44 +1,3 @@
-		[DllImport("gmime")]
-		static extern IntPtr g_mime_signature_validity_get_signers(IntPtr raw);
-
-		public IEnumerator Signers {
-			get { return new GMimeSignerIterator (this); }
-		}
-
-		internal class GMimeSignerIterator : IEnumerator {
-			GMime.SignatureValidity validity;
-			GMime.Signer signer;
-			int index = -1;
-
-			public GMimeSignerIterator (GMime.SignatureValidity validity)
-			{
-				this.validity = validity;
-			}
-			
-			public object Current {
-				get { return signer; }
-			}
-			
-			public void Reset ()
-			{
-				signer = null;
-				index = -1;
-			}
-			
-			public bool MoveNext ()
-			{
-				IntPtr rv;
-				
-				if (index == -1) {
-					rv = g_mime_signature_validity_get_signers (validity.Handle);
-					if (rv != IntPtr.Zero)
-						signer = (GMime.Signer) GLib.Opaque.GetOpaque (rv, typeof (GMime.Signer), false);
-				} else {
-					signer = signer.Next ();
-				}
-				
-				index++;
-				
-				return signer != null;
-			}
+		public SignerCollection Signers {
+			get { return new SignerCollection (this); }
 		}
diff --git a/mono/SignerCollection.cs b/mono/SignerCollection.cs
index 3f67e79..358e3cd 100644
--- a/mono/SignerCollection.cs
+++ b/mono/SignerCollection.cs
@@ -4,30 +4,23 @@ using System.Runtime.InteropServices;
 
 namespace GMime {
 	public class SignerCollection : IList {
-		Signer[] signers;
+		ArrayList signers;
 		
 		internal SignerCollection (SignatureValidity validity)
 		{
 			Signer signer;
-			int count = 0;
-			int i = 0;
 			
-			signer = GetFirstSigner (validity);
-			while (signer != null) {
-				signer = signer.Next ();
-				count++;
-			}
+			signers = new ArrayList ();
 			
-			signers = new Signer [count];
 			signer = GetFirstSigner (validity);
 			while (signer != null) {
-				signers[i++] = signer;
+				signers.Add (signer);
 				signer = signer.Next ();
 			}
 		}
 		
 		public int Count {
-			get { return signers.Length; }
+			get { return signers.Count; }
 		}
 		
 		public bool IsFixedSize {
@@ -58,55 +51,32 @@ namespace GMime {
 		
 		public bool Contains (Signer signer)
 		{
-			if (signer == null)
-				return false;
-			
-			for (int i = 0; i < Count; i++) {
-				if (signers[i] == signer)
-					return true;
-			}
-			
-			return false;
+			return signers.Contains (signer);
 		}
 		
 		bool IList.Contains (object value)
 		{
-			return Contains (value as Signer);
+			return signers.Contains (value);
 		}
 		
 		public void CopyTo (Array array, int index)
 		{
-			if (array == null)
-				throw new ArgumentNullException ("array");
-			
-			if (index < 0)
-				throw new ArgumentOutOfRangeException ("index");
-			
-			for (int i = 0; i < Count; i++)
-				array.SetValue (((IList) this)[i], index + i);
+			signers.CopyTo (array, index);
 		}
 		
 		public IEnumerator GetEnumerator ()
 		{
-			return new SignerIterator (this);
+			return signers.GetEnumerator ();
 		}
 		
 		public int IndexOf (Signer signer)
 		{
-			if (signer == null)
-				return -1;
-			
-			for (int i = 0; i < Count; i++) {
-				if (signers[i] == signer)
-					return i;
-			}
-			
-			return -1;
+			return signers.IndexOf (signer);
 		}
 		
 		int IList.IndexOf (object value)
 		{
-			return IndexOf (value as Signer);
+			return signers.IndexOf (value);
 		}
 		
 		void IList.Insert (int index, object value)
@@ -126,10 +96,7 @@ namespace GMime {
 		
 		public Signer this[int index] {
 			get {
-				if (index > Count)
-					throw new ArgumentOutOfRangeException ("index");
-				
-				return signers[index];
+				return signers[index] as Signer;
 			}
 			
 			set {
@@ -139,7 +106,7 @@ namespace GMime {
 		
 		object IList.this[int index] {
 			get {
-				return this[index];
+				return signers[index];
 			}
 			
 			set {
@@ -159,31 +126,5 @@ namespace GMime {
 			
 			return (Signer) GLib.Opaque.GetOpaque (rv, typeof (Signer), false);
 		}
-		
-		internal class SignerIterator : IEnumerator {
-			SignerCollection signers;
-			int index = -1;
-			
-			public SignerIterator (SignerCollection signers)
-			{
-				this.signers = signers;
-			}
-			
-			public object Current {
-				get { return index >= 0 ? signers[index] : null; }
-			}
-			
-			public void Reset ()
-			{
-				index = -1;
-			}
-			
-			public bool MoveNext ()
-			{
-				index++;
-				
-				return index < signers.Count;
-			}
-		}
 	}
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]