// Copyright 2018 RED Software, LLC. All Rights Reserved.
using System.Collections.Generic;
namespace IgniteEngine
{
///
/// Class that extends the use of the List class.
///
public static class DictionaryExtensions
{
///
/// The object to lock for list access.
///
private static readonly object lockObject = new object();
///
/// Adds an object to the list in a thread-safe, exception-safe
/// manner.
///
/// The source list.
/// The value to add.
public static void AddSafe(this Dictionary source, TKey key, TValue value)
{
if (key == null || value == null)
{
return;
}
lock (lockObject)
{
if (source.ContainsKey(key))
{
source[key] = value;
return;
}
source.Add(key, value);
}
}
}
}