Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Created January 21, 2009 20:28
Show Gist options
  • Save atifaziz/50169 to your computer and use it in GitHub Desktop.
Save atifaziz/50169 to your computer and use it in GitHub Desktop.
Mono 2.0 to 2.2 LINQ diff
--- mono-2.0\mcs\class\System.Core\System.Linq\ChangeLog 2008-10-02 00:02:58.000000000 +0200
+++ mono-2.2\mcs\class\System.Core\System.Linq\ChangeLog 2008-11-11 06:01:12.000000000 +0100
@@ -2,11 +2,30 @@
* QueryableEnumerable.cs: fix ElementType.
+2008-09-28 Sebastien Pouliot <[email protected]>
+
+ * Enumerable.cs: Add missing cast Average on IEnumerable<long?> to
+ ensure the result is not truncated.
+ [Found using Gendarme's ReviewCastOnIntegerDivisionRule]
+
+2008-09-11 Jb Evain <[email protected]>
+
+ * Enumerable.cs (Iterate*): use a bool empty instead of an int counter.
+ Fixes #425344.
+
+2007-08-14 Marek Safar <[email protected]>
+
+ * Enumerable.cs (Cast): Simplified.
+
2008-08-08 Jb Evain <[email protected]>
* Enumerable.cs (Take): fix not too consume an uneeded item from
the source enumerable. Fix #415644.
+2008-07-24 Marek Safar <[email protected]>
+
+ * Enumerable.cs (First): Optimized.
+
2008-05-27 Jb Evain <[email protected]>
* Enumerable.cs (Sum): don't throw if source is empty.
--- mono-2.0\mcs\class\System.Core\System.Linq\Enumerable.cs 2008-09-02 18:45:30.000000000 +0200
+++ mono-2.2\mcs\class\System.Core\System.Linq\Enumerable.cs 2008-11-11 06:01:12.000000000 +0100
@@ -225,7 +225,7 @@
{
Check.Source (source);
- return source.AverageNullable<long, long, double> ((a, b) => a + b, (a, b) => a / b);
+ return source.AverageNullable<long, long, double> ((a, b) => a + b, (a, b) => (double) a / b);
}
public static double? Average (this IEnumerable<double?> source)
@@ -332,8 +332,8 @@
static IEnumerable<TResult> CreateCastIterator<TResult> (IEnumerable source)
{
- foreach (object element in source)
- yield return (TResult) element;
+ foreach (TResult element in source)
+ yield return element;
}
#endregion
@@ -579,7 +579,20 @@
{
Check.Source (source);
- return source.First (PredicateOf<TSource>.Always, Fallback.Throw);
+ var list = source as IList<TSource>;
+ if (list != null) {
+ if (list.Count != 0)
+ return list [0];
+
+ throw new InvalidOperationException ();
+ } else {
+ using (var enumerator = source.GetEnumerator ()) {
+ if (enumerator.MoveNext ())
+ return enumerator.Current;
+ }
+ }
+
+ throw new InvalidOperationException ();
}
public static TSource First<TSource> (this IEnumerable<TSource> source, Func<TSource, bool> predicate)
@@ -1056,7 +1069,7 @@
static T? IterateNullable<T> (IEnumerable<T?> source, T initValue, Func<T?, T?, bool> selector) where T : struct
{
- int counter = 0;
+ bool empty = true;
T? value = initValue;
foreach (var element in source) {
if (!element.HasValue)
@@ -1064,10 +1077,11 @@
if (selector (element.Value, value))
value = element;
- ++counter;
+
+ empty = false;
}
- if (counter == 0)
+ if (empty)
return null;
return value;
@@ -1142,13 +1156,13 @@
static U Iterate<T, U> (IEnumerable<T> source, U initValue, Func<T, U, U> selector)
{
- int counter = 0;
+ bool empty = true;
foreach (var element in source) {
initValue = selector (element, initValue);
- ++counter;
+ empty = false;
}
- if (counter == 0)
+ if (empty)
throw new InvalidOperationException ();
return initValue;
@@ -1156,17 +1170,17 @@
static U? IterateNullable<T, U> (IEnumerable<T> source, U initialValue, Func<T, U?, U?> selector) where U : struct
{
- int counter = 0;
+ bool empty = true;
U? value = initialValue;
foreach (var element in source) {
value = selector (element, value);
if (!value.HasValue)
continue;
- ++counter;
+ empty = false;
}
- if (counter == 0)
+ if (empty)
return null;
return value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment