System.Collections.Generic.ICollection.Contains(TK)

Here are the examples of the csharp api System.Collections.Generic.ICollection.Contains(TK) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : DictionaryDrawer.cs
with MIT License
from luis-l

TK GetNewKey(IDictionary<TK, TV> from)
        {
            TK key;

            if (typeof(TK) == typeof(string))
            {
                string prefix;
                int postfix;
                if (from.Count > 0)
                {
                    prefix = from.Last().Key as string;
                    string postfixStr = "";
                    int i = prefix.Length - 1; 
                    for (; i >= 0; i--)
                    {
                        char c = prefix[i];
                        if (!char.IsDigit(c))
                            break;
                        postfixStr = postfixStr.Insert(0, c.ToString());
                    }
                    if (int.TryParse(postfixStr, out postfix))
                        prefix = prefix.Remove(i + 1, postfixStr.Length);
                }
                else
                { 
                    prefix = "New Key ";
                    postfix = 0;
                }
                while(from.Keys.Contains((TK)(object)(prefix + postfix))) postfix++;
                key = (TK)(object)(prefix + postfix);
            }
            else if (typeof(TK) == typeof(int))
            {
                var n = 0;
                while (from.Keys.Contains((TK)(object)(n))) n++;
                key = (TK)(object)n;
            }
            else if (typeof(TK).IsEnum)
            {
                var values = Enum.GetValues(typeof(TK)) as TK[];
                var result = values.Except(from.Keys).ToList();
                if (result.Count == 0)
                    return default(TK);
                key = (TK)result[0];
            }
            else key = default(TK);

            return key;
        }