Purpose of code changes on this branch:
Porting morelinq to the Mono Platform. The Mono Port targets the runtime
version corresponding
to .NET 3.5. This review request does not treat
a possible the Silverlight->Moonlight port.
The existing project solution can be easily opened and compiled with
MonoDevelop (v.2.2.x).
MonoDevelop also provides out of the box
Integration with NUnit, there is no (!) configuration necessary to run the test
project. Simply
choose "run element" from the test projects context-
menu.
Morelinq does use Warning Level 4 and the "treat Warnings as Errors" options. I
advocate this
usage. However, it seems gmcs (the Mono C#3.0
compiler) is a little stricter in terms of warnings than Mircosoft's csc.
This causes one error in the MoreLinq main project, which can be easily fixed
via supressing this
error. It can be discussed if we should introduce
conditional compilation (in this case preprocessing) here, although I don't
think it makes much
sense yet.
Index: trunk/MoreLinq/Consume.cs
===========================================================
========
--- trunk/MoreLinq/Consume.cs (revision 151)
+++ trunk/MoreLinq/Consume.cs (working copy)
@@ -1,4 +1,4 @@
-Ôªø#region License and Terms
+#region License and Terms
//
// MoreLINQ - Extensions to LINQ to Objects
// Copyright (c) 2008-9 Jonathan Skeet. All rights reserved.
@@ -32,8 +32,13 @@
public static void Consume<T>(this IEnumerable<T> source)
{
source.ThrowIfNull("source");
+
+ // Disable Warning CS0219: The variable element is assigned but its value
is never
used
+ // This is only necessary when compiling for mono
+ #pragma warning disable 0219
foreach (T element in source)
{
+
}
}
}
Porting is more difficult in the testing project. For some reason gmcs does not
like the private
DisposeTestingSequenceEnumerator class nested
in TestingSequnce<T>, it assumes access to the Disposed event would be
impossible due to it's
protection level (which is wrong IMHO). I will
further discuss this problem on the Mono mailing list, however I think it
doesn't hurt too much
moving DisposeTestingSequenceEnumerator out
of TestingSequence and making it a seperate class. I still end up with a CS0067
warning (event
not used) on the event, which needs to be fixed.
As a side note, it should be discussed to which naming convention for member
variables this
code should stick to, at the moment there it is
none, making it difficult to separate between method locals and class members.
And I think
copying the Event variable in Dispose() is
unnecessary too.
Index: trunk/MoreLinq.Test/TestingSequence.cs
===========================================================
========
--- trunk/MoreLinq.Test/TestingSequence.cs (revision 151)
+++ trunk/MoreLinq.Test/TestingSequence.cs (working copy)
@@ -1,4 +1,4 @@
-Ôªøusing System;
+using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
@@ -13,7 +13,56 @@
return new TestingSequence<T>(elements);
}
}
+
+ /// <summary>
+ /// The actual enumerator used by <see cref"TestingSequence(Of T)">.
+ /// </summary>
+ /// <remarks>
+ /// This class should not be used directly. Normally this would have been a
private nested
class of TestingSequence, this breaks
+ /// </remarks>
+ internal class DisposeTestingSequenceEnumerator<T> : IEnumerator<T>
+ {
+ private readonly IEnumerator<T> sequence;
+ // Disable Warning CS0067: The event
`MoreLinq.Test.DisposeTestingSequenceEnumerator<T>.Disposed' is never used
+ // This is only necessary when compiling for mono
+ #pragma warning disable 0067
+ public event EventHandler Disposed;
+
+ public DisposeTestingSequenceEnumerator(IEnumerator<T> sequence)
+ {
+ this.sequence = sequence;
+ }
+
+ public T Current
+ {
+ get { return sequence.Current; }
+ }
+
+ public void Dispose()
+ {
+ sequence.Dispose();
+ var disposed = Disposed;
+ if (disposed != null)
+ disposed(this, EventArgs.Empty);
+ }
+
+ object IEnumerator.Current
+ {
+ get { return Current; }
+ }
+
+ public bool MoveNext()
+ {
+ return sequence.MoveNext();
+ }
+
+ public void Reset()
+ {
+ sequence.Reset();
+ }
+ }
+
/// <summary>
/// Sequence that asserts whether its iterator has been disposed
/// when it is disposed itself and also whether GetEnumerator() is
@@ -46,7 +95,7 @@
public IEnumerator<T> GetEnumerator()
{
Assert.That(this.sequence, Is.Not.Null, "LINQ operators should not enumerate a sequence
more than once.");
- var enumerator = new
DisposeTestingSequenceEnumerator(this.sequence.GetEnumerator());
+ var enumerator = new
DisposeTestingSequenceEnumerator<T>(this.sequence.GetEnumerator());
enumerator.Disposed += delegate { disposed = true; };
this.sequence = null;
return enumerator;
@@ -56,45 +105,5 @@
{
return GetEnumerator();
}
-
- private class DisposeTestingSequenceEnumerator : IEnumerator<T>
- {
- private readonly IEnumerator<T> sequence;
-
- public event EventHandler Disposed;
-
- public DisposeTestingSequenceEnumerator(IEnumerator<T> sequence)
- {
- this.sequence = sequence;
- }
-
- public T Current
- {
- get { return sequence.Current; }
- }
-
- public void Dispose()
- {
- sequence.Dispose();
- var disposed = Disposed;
- if (disposed != null)
- disposed(this, EventArgs.Empty);
- }
-
- object IEnumerator.Current
- {
- get { return Current; }
- }
-
- public bool MoveNext()
- {
- return sequence.MoveNext();
- }
-
- public void Reset()
- {
- sequence.Reset();
- }
- }
- }
+ }
}
Next two problems are MinBy and MaxBy tests, somehow the extension method on
null value
usage confuses gmcs and let's it generate a
Warning CS1720: Expression will always cause a `System.NullReferenceException'.
Our test could
not prove any better this warning is invalid ;-)
Index: trunk/MoreLinq.Test/MinByTest.cs
===========================================================
========
--- trunk/MoreLinq.Test/MinByTest.cs (revision 151)
+++ trunk/MoreLinq.Test/MinByTest.cs (working copy)
@@ -1,4 +1,4 @@
-Ôªøusing System;
+using System;
using System.Collections.Generic;
using NUnit.Framework;
@@ -11,6 +11,9 @@
[ExpectedException(typeof(ArgumentNullException))]
public void MinByNullSequence()
{
+ // Disable Warning CS1720: Expression will always cause a
`System.NullReferenceException'
+ // This is only necessary when compiling for mono
+ #pragma warning disable 1720
((IEnumerable<string>)null).MinBy(x => x.Length);
}
Index: trunk/MoreLinq.Test/MaxByTest.cs
===========================================================
========
--- trunk/MoreLinq.Test/MaxByTest.cs (revision 151)
+++ trunk/MoreLinq.Test/MaxByTest.cs (working copy)
@@ -1,4 +1,4 @@
-Ôªøusing System;
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using NUnit.Framework;
@@ -12,6 +12,9 @@
[ExpectedException(typeof(ArgumentNullException))]
public void MaxByNullSequence()
{
+ // Disable Warning CS1720: Expression will always cause a
`System.NullReferenceException'
+ // This is only necessary when compiling for mono
+ #pragma warning disable 1720
((IEnumerable<string>)null).MaxBy(x => x.Length);
}
I have attached a complete patch. For some reason google code doesn't support
patch review, so
don't get confused by the branch stuff.
Original issue reported on code.google.com by jojo.rudolph@googlemail.com on 8 Apr 2010 at 4:51
Original issue reported on code.google.com by
jojo.rudolph@googlemail.com
on 8 Apr 2010 at 4:51