예제 #1
0
        private void AddNewPair()
        {
            TK defKey;

            if (typeof(TK) == typeof(string))
            {
                var x = "New Key ";
                var n = 0;
                while (_kvpList.Keys.Contains((TK)(object)(x + n)))
                {
                    n++;
                }
                defKey = (TK)(object)(x + n);
            }
            else if (typeof(TK) == typeof(int))
            {
                var n = 0;
                while (_kvpList.Keys.Contains((TK)(object)(n)))
                {
                    n++;
                }
                defKey = (TK)(object)n;
            }
            else if (typeof(TK).IsEnum)
            {
                var values = Enum.GetValues(typeof(TK)) as TK[];
                var result = values.Except(_kvpList.Keys).ToList();
                if (result.Count == 0)
                {
                    return;
                }
                defKey = (TK)result[0];
            }
            else
            {
                defKey = default(TK);
            }

            try
            {
                var defValue = default(TV);
                _kvpList.Insert(0, defKey, defValue);
                memberValue.Add(defKey, defValue);

                var eKey = RuntimeHelper.CombineHashCodes(id, (_kvpList.Count - 1), "entry");
                foldouts[eKey] = true;
            }
            catch (ArgumentException)
            {
                Log("Key already exists: " + defKey);
            }
        }
예제 #2
0
        private void AddNewPair()
        {
            try
            {
                var key   = getNewKey();
                var value = default(TV);
                kvpList.Insert(0, key, value, false);

                var pkey = RuntimeHelper.CombineHashCodes(id, (kvpList.Count - 1), "entry");
                foldouts[pkey] = true;
            }
            catch (ArgumentException e)
            {
                Log(e.Message);
            }
        }