namespace Sandbox;
public static partial class SandboxSystemExtensions
{
///
/// If the key doesn't exist it is created and returned
///
public static TValue GetOrCreate( this IDictionary dict, TKey key ) where TValue : new()
{
TValue val;
if ( dict.TryGetValue( key, out val ) )
return val;
val = new TValue();
dict.Add( key, val );
return val;
}
///
/// Clones the dictionary. Doesn't clone the values.
///
public static Dictionary Clone( this Dictionary dict )
{
Dictionary ret = new Dictionary( dict.Count, dict.Comparer );
foreach ( KeyValuePair entry in dict )
{
ret.Add( entry.Key, (TValue)entry.Value );
}
return ret;
}
}