/* * This file is part of the "TinaX Framework". * https://github.com/yomunsam/TinaX * * (c) Nekonya Studio * https://nekonya.io * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ using System.Collections.Generic; namespace TinaX { public static class DictionaryExtension { /// /// If not empty , return true, else return false /// /// /// /// /// /// /// If not empty , return true, else return false public static bool AddIfNotExist(this IDictionary dict, TKey key, TValue value) { if (!dict.ContainsKey(key)) { dict.Add(key, value); return true; } return false; } /// /// If key not exist , add key-value , or override value. /// /// /// /// /// /// public static void AddOrOverride(this IDictionary dict, TKey key, TValue value) { if (!dict.ContainsKey(key)) dict.Add(key, value); else dict[key] = value; } } }