diff --git a/CSharp.lua/CoreSystem.Lua/CoreSystem/Collections/Dictionary.lua b/CSharp.lua/CoreSystem.Lua/CoreSystem/Collections/Dictionary.lua index 10455e42..75060388 100644 --- a/CSharp.lua/CoreSystem.Lua/CoreSystem/Collections/Dictionary.lua +++ b/CSharp.lua/CoreSystem.Lua/CoreSystem/Collections/Dictionary.lua @@ -356,6 +356,15 @@ local Dictionary = { end return remove(this, key) end, + TryAdd = function (this, key, value) + if key == nil then throw(ArgumentNullException("key")) end + local exists, currentValue = this:TryGetValue(key) + if exists then + return false + end + this:set(key, value) + return true + end, TryGetValue = function (this, key) if key == nil then throw(ArgumentNullException("key")) end local value = this[key] @@ -633,6 +642,15 @@ local ArrayDictionary = (function () end return false end, + TryAdd = function (this, key, value) + if key == nil then throw(ArgumentNullException("key")) end + local exists, currentValue = this:TryGetValue(key) + if exists then + return false + end + this:set(key, value) + return true + end, TryGetValue = function (this, key) if key == nil then throw(ArgumentNullException("key")) end local len = #this