[Mono-dev] Patch for compiling PagedDataSource in Grasshopper
Eyal Alaluf
eyala at mainsoft.com
Tue Sep 13 09:29:32 EDT 2005
Hi, all.
The issue handled is the use of yield in PagedDataSource.cs. I rewrote this under
#if TARGET_JVM.
I'd rather have one code base for this (removing the use of yield from the Mono code).
I don't see any advantage here for having the two codes side by side.
The main thing I am missing is a good test for PagedDataSource.cs to verify that a fix without
#if will work well for Mono.
Eyal.
-------------- next part --------------
Index: System.Web.UI.WebControls/PagedDataSource.cs
===================================================================
--- System.Web.UI.WebControls/PagedDataSource.cs (revision 49680)
+++ System.Web.UI.WebControls/PagedDataSource.cs (working copy)
@@ -240,10 +240,81 @@
return String.Empty; // as documented
}
+#if TARGET_JVM
+ internal class ListEnum : IEnumerator
+ {
+ int start;
+ int end;
+ int ind;
+ IList list;
+
+ internal ListEnum(IList list, int start, int end)
+ {
+ this.list = list;
+ this.start = start;
+ this.end = end;
+ this.ind = start - 1;
+ }
+
+ public bool MoveNext()
+ {
+ ind++;
+ return (ind < end);
+ }
+
+ public void Reset() { ind = start - 1; }
+ public object Current { get { return list[ind]; }}
+ }
+
private IEnumerator GetListEnum (IList list, int start, int end)
{
if (!AllowPaging)
end = list.Count;
+ return new ListEnum(list, start, end);
+ }
+
+ internal class EnumeratorEnum : IEnumerator
+ {
+ int start;
+ int end;
+ int ind;
+ IEnumerator en;
+ PagedDataSource parent;
+
+ internal EnumeratorEnum(PagedDataSource parent, IEnumerator en, int start, int end)
+ {
+ this.parent = parent;
+ this.en = en;
+ this.start = start;
+ this.end = end;
+ this.ind = start - 1;
+ for (int i = 0; i < start; i++)
+ en.MoveNext ();
+ }
+
+ public bool MoveNext()
+ {
+ ind++;
+ return (!parent.allow_paging || ind < end) && en.MoveNext ();
+ }
+
+ public void Reset()
+ {
+ throw new NotSupportedException();
+ }
+
+ public object Current { get { return en.Current; }}
+ }
+
+ private IEnumerator GetEnumeratorEnum (IEnumerator e, int start, int end)
+ {
+ return new EnumeratorEnum(this, e, start, end);
+ }
+#else
+ private IEnumerator GetListEnum (IList list, int start, int end)
+ {
+ if (!AllowPaging)
+ end = list.Count;
for (int i = start; i < end; i++)
yield return list [i];
}
@@ -255,5 +326,6 @@
for (int i = start; (!allow_paging || i < end) && e.MoveNext (); i++)
yield return e.Current;
}
+#endif
}
}
More information about the Mono-devel-list
mailing list