Beispiel #1
0
        /// <summary>
        /// Returns a sequence the key-values.
        /// Ex: Key Value Key Value ... etc...
        /// </summary>
        public static IEnumerable <String> Sequence <TKey, TValue>(IEnumerable <KeyValuePair <TKey, TValue> > enumeration)
        {
            var formatKey   = FormatterHelper.StringFormatter <TKey>();
            var formatValue = FormatterHelper.StringFormatter <TValue>();

            foreach (var item in enumeration)
            {
                yield return(formatKey(item.Key));

                yield return(formatValue(item.Value));
            }
        }
        public IDictionary <TKey, TValue> AsDictionaryCollation <TKey, TValue>()
        {
            CheckException();

            var dictionary = new Dictionary <TKey, TValue>();
            var complex    = _response.Cast <RESPArray>();

            var keyFormatter   = FormatterHelper.Formatter <TKey>();
            var valueFormatter = FormatterHelper.Formatter <TValue>();

            try
            {
                for (int i = 0; i < complex.Count; i += 2)
                {
                    dictionary.Add(keyFormatter(complex[i]), valueFormatter(i < complex.Count ? complex[i + 1] : null));
                }
            }
            catch (Exception ex)
            {
                throw new RedisClientBindingException(String.Format("Cannot create Dictionary<{0},{1}> from response to command in line number {2}.", typeof(TKey).Name, typeof(TValue).Name, _lineNumber), ex);
            }

            return(dictionary);
        }