Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 41 posts 70 karma points
    Aug 09, 2017 @ 13:15
    Dan
    0

    Handle duplicate keys

    I'm using this in a site but because there's no validation on the keys, I've been getting the dreaded error "An item with the same key has already been added."

    Just add this to the KeyValueEditorValueConverter line 42

    var uniqueValues = pairs.GroupBy(pair => pair.Key)
                         .Select(group => group.First())
                         .ToDictionary(pair => pair.Key, pair => pair.Value);
    
            foreach (var pair in uniqueValues)
            {
                retval.Add(pair.Key, pair.Value);
            }
    
Please Sign in or register to post replies

Write your reply to:

Draft