public virtual string GetItemKey <T>(string value) { var pi = StoreEntityTypesCache.GetTypeKey(typeof(T)); var key = string.Format("[{0}_{1}:{2}]", typeof(T).Name, pi.Name, value); return(key); }
public virtual string GetItemKey <T>(T item) { if (item == null) { throw new ArgumentNullException("Item cannot be null"); } var pi = StoreEntityTypesCache.GetTypeKey(typeof(T)); var key = string.Format("[{0}_{1}:{2}]", typeof(T).Name, pi.Name, GetStringValue(pi.GetValue(item, null))); return(key); }
private Dictionary <string, string> Serialize <T>(T item, bool partial = false) { var result = new Dictionary <string, string>(); var properties = partial ? StoreEntityTypesCache.GetTypePartialValueProperties(typeof(T)) : StoreEntityTypesCache.GetTypeProperties(typeof(T)); if (properties != null) { foreach (var pi in properties.Values) { result.Add(pi.Name, GetStringValue((pi.GetValue(item, null) ?? string.Empty)).ToString()); } } return(result); }
public virtual void Set <T>(T item) { var key = GetItemKey(item); // Write value Provider.Hash[key].Set(Serialize(item)); // Write indexes var keyvalue = GetStringValue(StoreEntityTypesCache.GetTypeKey(typeof(T)).GetValue(item, null)); var indexes = StoreEntityTypesCache.GetTypeIndexes(typeof(T)); if (indexes != null) { foreach (var idx in indexes.Values) { Provider.Set[GetIndexKey(item, idx)].Add(keyvalue); } } }
private void InternalDeserializeValue <T>(T newitem, KeyValuePair <string, string>[] values, bool partial) { if (values != null) { var properties = partial ? StoreEntityTypesCache.GetTypePartialValueProperties(typeof(T)) : StoreEntityTypesCache.GetTypeProperties(typeof(T)); if (properties != null) { foreach (var kvp in values) { if (!string.IsNullOrEmpty(kvp.Value) && properties.ContainsKey(kvp.Key)) { var pi = properties[kvp.Key]; pi.SetValue(newitem, ConvertTo(pi.PropertyType, kvp.Value), null); } } } } }