[PATCH] null keys in Lookup<>

View: New views
4 Messages — Rating Filter:   Alert me  

[PATCH] null keys in Lookup<>

by Eric Maupin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

.NET supports null keys for groupings in Enumerable.ToLookup()/Lookup<>, here's a patch for review to improve Mono compatibility.

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@...
http://lists.ximian.com/mailman/listinfo/mono-devel-list

System.Core NullKeyLookup.diff (5K) Download Attachment

Re: [PATCH] null keys in Lookup<>

by Jb Evain-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey,

On 11/10/09, ermau <me@...> wrote:
> .NET supports null keys for groupings in
> Enumerable.ToLookup()/Lookup<>, here's a patch for review
> to improve Mono compatibility.

+ Assert.IsTrue (l[null].Contains ("2"));

Please add a space before indexing, like you do before calling a method.

+ }
+ else if (!dictionary.TryGetValue (key, out list)) {

Put the else on the same line as the }

+ if (key == null && nullGrouping != null)
+ return nullGrouping;
+ else
+ {
+ IGrouping<TKey, TElement> group;
+ if (groups.TryGetValue (key, out group))
+ return group;
+ }

Remove the else and move the code to the same level as the if.

When it's done please go ahead and commit to trunk and mono-2-6.

Thanks!

--
Jb Evain  <jb@...>
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@...
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Re: [PATCH] null keys in Lookup<>

by Eric Maupin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In reviewing removing the else, I realized there was a bug to begin with. Made your other requested changes, added a test for the bug and fixed it.

On Tue, Nov 10, 2009 at 13:36, Jb Evain <jb@...> wrote:
Hey,

On 11/10/09, ermau <me@...> wrote:
> .NET supports null keys for groupings in
> Enumerable.ToLookup()/Lookup<>, here's a patch for review
> to improve Mono compatibility.

+                       Assert.IsTrue (l[null].Contains ("2"));

Please add a space before indexing, like you do before calling a method.

+                               }
+                               else if (!dictionary.TryGetValue (key, out list)) {

Put the else on the same line as the }

+                               if (key == null && nullGrouping != null)
+                                       return nullGrouping;
+                               else
+                               {
+                                       IGrouping<TKey, TElement> group;
+                                       if (groups.TryGetValue (key, out group))
+                                               return group;
+                               }

Remove the else and move the code to the same level as the if.

When it's done please go ahead and commit to trunk and mono-2-6.

Thanks!

--
Jb Evain  <jb@...>



_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@...
http://lists.ximian.com/mailman/listinfo/mono-devel-list

System.Core.diff (6K) Download Attachment

Re: [PATCH] null keys in Lookup<>

by Eric Maupin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So, note to self, don't write BCL code when distracted and you should be doing other things. Added a few more tests and fixed Contains and GetEnumerator.

On Tue, Nov 10, 2009 at 15:43, ermau <me@...> wrote:
In reviewing removing the else, I realized there was a bug to begin with. Made your other requested changes, added a test for the bug and fixed it.

On Tue, Nov 10, 2009 at 13:36, Jb Evain <jb@...> wrote:
Hey,

On 11/10/09, ermau <me@...> wrote:
> .NET supports null keys for groupings in
> Enumerable.ToLookup()/Lookup<>, here's a patch for review
> to improve Mono compatibility.

+                       Assert.IsTrue (l[null].Contains ("2"));

Please add a space before indexing, like you do before calling a method.

+                               }
+                               else if (!dictionary.TryGetValue (key, out list)) {

Put the else on the same line as the }

+                               if (key == null && nullGrouping != null)
+                                       return nullGrouping;
+                               else
+                               {
+                                       IGrouping<TKey, TElement> group;
+                                       if (groups.TryGetValue (key, out group))
+                                               return group;
+                               }

Remove the else and move the code to the same level as the if.

When it's done please go ahead and commit to trunk and mono-2-6.

Thanks!

--
Jb Evain  <jb@...>




_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@...
http://lists.ximian.com/mailman/listinfo/mono-devel-list

System.Core.diff (9K) Download Attachment