mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-04 20:38:24 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
35 lines
831 B
C#
35 lines
831 B
C#
|
|
namespace Sandbox;
|
|
|
|
public static partial class SandboxSystemExtensions
|
|
{
|
|
/// <summary>
|
|
/// If the key doesn't exist it is created and returned
|
|
/// </summary>
|
|
public static TValue GetOrCreate<TKey, TValue>( this IDictionary<TKey, TValue> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clones the dictionary. Doesn't clone the values.
|
|
/// </summary>
|
|
public static Dictionary<TKey, TValue> Clone<TKey, TValue>( this Dictionary<TKey, TValue> dict )
|
|
{
|
|
Dictionary<TKey, TValue> ret = new Dictionary<TKey, TValue>( dict.Count, dict.Comparer );
|
|
|
|
foreach ( KeyValuePair<TKey, TValue> entry in dict )
|
|
{
|
|
ret.Add( entry.Key, (TValue)entry.Value );
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
}
|