/// <summary> /// Copies the elements of the <see cref="T:System.Collections.Generic.ICollection`1" /> to an <see cref="T:System.Array" />, starting at a particular <see cref="T:System.Array" /> index. /// </summary> /// <param name="array">The one-dimensional <see cref="T:System.Array" /> that is the destination of the elements copied from <see cref="T:System.Collections.Generic.ICollection`1" />. The <see cref="T:System.Array" /> must have zero-based indexing.</param> /// <param name="arrayIndex">The zero-based index in <paramref name="array" /> at which copying begins.</param> public void CopyTo(KeyValuePair <TKey, TValue>[] array, int arrayIndex) { var values = RedisDb.HashGetAll(RedisKey); for (var i = 0; i < values.Length; i++) { var key = KeySerializer.Deserialize <TKey>(values[i].Name); var value = ValueSerializer.Deserialize <TValue>(values[i].Value); array[i + arrayIndex] = new KeyValuePair <TKey, TValue>(key, value); } }
private void Deserialize <T>(List <T> obj) { Type t = typeof(T); RedisValue[] redisValues = RedisDb.SortedSetRangeByScore(t.GetTypeInfo().Name); foreach (string redisValue in redisValues) { T tobj = (T)Activator.CreateInstance(t); HashEntry[] hashEntries = RedisDb.HashGetAll(redisValue); foreach (var property in t.GetProperties()) { try { if (property.PropertyType == typeof(Int32)) { property.SetValue(tobj, JsonConvert.DeserializeObject <Int32>( hashEntries.First(x => x.Name == property.Name).Value)); } else if (property.PropertyType == typeof(List <string>)) { property.SetValue(tobj, JsonConvert.DeserializeObject <List <string> >( hashEntries.First(x => x.Name == property.Name).Value)); } else { property.SetValue(tobj, JsonConvert.DeserializeObject( hashEntries.First(x => x.Name == property.Name).Value)); } } catch { } } obj.Add(tobj); } }
private void Deserialize <T>(T obj) { Type t = typeof(T); HashEntry[] hashEntries = RedisDb.HashGetAll(t.Name); try { foreach (var property in t.GetProperties()) { try { if (property.PropertyType == typeof(Int32)) { property.SetValue(obj, JsonConvert.DeserializeObject <Int32>( hashEntries.First(x => x.Name == property.Name).Value)); } else if (property.PropertyType == typeof(List <string>)) { property.SetValue(obj, JsonConvert.DeserializeObject <List <string> >( hashEntries.First(x => x.Name == property.Name).Value)); } else { property.SetValue(obj, JsonConvert.DeserializeObject( hashEntries.First(x => x.Name == property.Name).Value)); } } catch {} } } catch { } }