wasSharp

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 45  →  ?path2? @ 44
/Collections/Utilities/CollectionExtensions.cs
@@ -7,7 +7,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using wasSharp.Collections.Specialized;
 
namespace wasSharp.Collections.Utilities
@@ -34,6 +33,36 @@
.OrderBy(kvp => kvp.Key));
}
 
public static void UnionWith<TKey, TValue>(this IDictionary<TKey, TValue> target,
IDictionary<TKey, TValue> source)
{
var LockObject = new object();
source.AsParallel().ForAll(o =>
{
bool hasElement;
lock (LockObject)
{
hasElement = target.ContainsKey(o.Key);
}
switch (hasElement)
{
case true:
lock (LockObject)
{
target[o.Key] = o.Value;
}
break;
 
default:
lock (LockObject)
{
target.Add(o.Key, o.Value);
}
break;
}
});
}
 
public static void AddOrReplace<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
{
switch (dictionary.ContainsKey(key))