Example #1
0
        public static void LoopModifiable <TKey, TValue>(IDictionary <TKey, TValue> dictionary, BreakableKeyValueCallback <TKey, TValue> keyValueCallback)
        {
            if (dictionary == null || dictionary.Count == 0)
            {
                return;
            }
            Dictionary <TKey, TValue> cloneDict;

            if (dictionary is IdentityDictionary <TKey, TValue> )
            {
                cloneDict = new IdentityDictionary <TKey, TValue>(dictionary);
            }
            else
            {
                cloneDict = new Dictionary <TKey, TValue>(dictionary);
            }
            using (IEnumerator <KeyValuePair <TKey, TValue> > dictIter = cloneDict.GetEnumerator())
            {
                while (dictIter.MoveNext())
                {
                    KeyValuePair <TKey, TValue> entry = dictIter.Current;
                    if (!keyValueCallback.Invoke(entry.Key, entry.Value))
                    {
                        return;
                    }
                }
            }
        }
Example #2
0
 public static void Loop <TKey, TValue>(IDictionary <TKey, TValue> dictionary, BreakableKeyValueCallback <TKey, TValue> keyValueCallback)
 {
     if (dictionary == null || dictionary.Count == 0)
     {
         return;
     }
     using (IEnumerator <KeyValuePair <TKey, TValue> > dictIter = dictionary.GetEnumerator())
     {
         while (dictIter.MoveNext())
         {
             KeyValuePair <TKey, TValue> entry = dictIter.Current;
             if (!keyValueCallback.Invoke(entry.Key, entry.Value))
             {
                 return;
             }
         }
     }
 }
Example #3
0
 public static void Loop <TKey, TValue>(IEnumerator <KeyValuePair <TKey, TValue> > dictIter, BreakableKeyValueCallback <TKey, TValue> keyValueCallback)
 {
     try
     {
         while (dictIter.MoveNext())
         {
             KeyValuePair <TKey, TValue> entry = dictIter.Current;
             if (!keyValueCallback.Invoke(entry.Key, entry.Value))
             {
                 return;
             }
         }
     }
     finally
     {
         dictIter.Reset();
     }
 }