[gmime] Simplified GetEnumerator() implementations.



commit 9dd62ec985013dd4f64480ea740d294f0effb99e
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Sun Aug 14 21:57:03 2011 -0400

    Simplified GetEnumerator() implementations.
    
    2011-08-14  Jeffrey Stedfast  <fejj gnome org>
    
    	* mono/*.custom: Simplified the GetEnumerator() implementations.

 ChangeLog                         |    2 ++
 mono/CertificateCollection.custom |   33 ++++++---------------------------
 mono/InternetAddressList.custom   |   33 ++++++---------------------------
 mono/SignatureCollection.custom   |   33 ++++++---------------------------
 4 files changed, 20 insertions(+), 81 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index de1b4b1..008caf9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2011-08-14  Jeffrey Stedfast  <fejj gnome org>
 
+	* mono/*.custom: Simplified the GetEnumerator() methods.
+
 	* mono/HeaderEnumerator.cs: New IEnumerator class returned by
 	HeaderList.GetEnumerator(). Wraps HeaderIter, providing a more
 	C#-like experience.
diff --git a/mono/CertificateCollection.custom b/mono/CertificateCollection.custom
index a7ab8b7..518e512 100644
--- a/mono/CertificateCollection.custom
+++ b/mono/CertificateCollection.custom
@@ -146,7 +146,12 @@
 		
 		public IEnumerator GetEnumerator ()
 		{
-			return new CertificateCollectionIterator (this);
+			int n = Count;
+			
+			for (int i = 0; i < n; i++)
+				yield return this[i];
+			
+			yield break;
 		}
 		
 		public int IndexOf (Certificate cert)
@@ -236,29 +241,3 @@
 				this[index] = value as Certificate;
 			}
 		}
-		
-		internal class CertificateCollectionIterator : IEnumerator {
-			CertificateCollection list;
-			int index = -1;
-			
-			public CertificateCollectionIterator (CertificateCollection list)
-			{
-				this.list = list;
-			}
-			
-			public object Current {
-				get { return list[index]; }
-			}
-			
-			public void Reset ()
-			{
-				index = -1;
-			}
-			
-			public bool MoveNext ()
-			{
-				index++;
-				
-				return index < list.Count;
-			}
-		}
diff --git a/mono/InternetAddressList.custom b/mono/InternetAddressList.custom
index 2563bdd..29d5ad9 100644
--- a/mono/InternetAddressList.custom
+++ b/mono/InternetAddressList.custom
@@ -155,7 +155,12 @@
 		
 		public IEnumerator GetEnumerator ()
 		{
-			return new InternetAddressListIterator (this);
+			int n = Count;
+			
+			for (int i = 0; i < n; i++)
+				yield return this[i];
+			
+			yield break;
 		}
 		
 		public int IndexOf (InternetAddress addr)
@@ -274,29 +279,3 @@
 		{
 			return ToString (false);
 		}
-		
-		internal class InternetAddressListIterator : IEnumerator {
-			InternetAddressList list;
-			int index = -1;
-			
-			public InternetAddressListIterator (InternetAddressList list)
-			{
-				this.list = list;
-			}
-			
-			public object Current {
-				get { return list[index]; }
-			}
-			
-			public void Reset ()
-			{
-				index = -1;
-			}
-			
-			public bool MoveNext ()
-			{
-				index++;
-				
-				return index < list.Count;
-			}
-		}
diff --git a/mono/SignatureCollection.custom b/mono/SignatureCollection.custom
index a5a95e4..332cadc 100644
--- a/mono/SignatureCollection.custom
+++ b/mono/SignatureCollection.custom
@@ -146,7 +146,12 @@
 		
 		public IEnumerator GetEnumerator ()
 		{
-			return new SignatureCollectionIterator (this);
+			int n = Count;
+			
+			for (int i = 0; i < n; i++)
+				yield return this[i];
+			
+			yield break;
 		}
 		
 		public int IndexOf (Signature signature)
@@ -236,29 +241,3 @@
 				this[index] = value as Signature;
 			}
 		}
-		
-		internal class SignatureCollectionIterator : IEnumerator {
-			SignatureCollection list;
-			int index = -1;
-			
-			public SignatureCollectionIterator (SignatureCollection list)
-			{
-				this.list = list;
-			}
-			
-			public object Current {
-				get { return list[index]; }
-			}
-			
-			public void Reset ()
-			{
-				index = -1;
-			}
-			
-			public bool MoveNext ()
-			{
-				index++;
-				
-				return index < list.Count;
-			}
-		}



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