public Action <T, T> GetMerger(CacheMember member) { if (CacheMergers.ContainsKey(member.Key)) { return(CacheMergers[member.Key]); } else { return(null); } }
public CacheMapRule <T> AddMember(Expression <Func <T, RedisValue> > fetcher, string key = null) { var unaryExpression = (UnaryExpression)fetcher.Body; while (unaryExpression.Operand.NodeType == ExpressionType.Convert) //Strip casts { unaryExpression = (UnaryExpression)unaryExpression.Operand; } var memberExp = (MemberExpression)unaryExpression.Operand; var accessor = fetcher.Compile(); var prefixes = new List <string>(); MemberInfo rootMember = null; if (memberExp.Expression.NodeType == ExpressionType.MemberAccess) { MemberExpression subExpression = (MemberExpression)memberExp.Expression; do { if (rootMember == null) { rootMember = subExpression.Member; } prefixes.Add(subExpression.Member.Name); if (subExpression.Expression.NodeType != ExpressionType.MemberAccess) { break; } subExpression = (MemberExpression)subExpression.Expression; } while (true); } if (rootMember == null) { rootMember = memberExp.Member; } // string strPrefix = string.Join(".", prefixes.ToArray()); // if (strPrefix.Length > 0) strPrefix += "."; //var cMember = new CacheMember(strPrefix, (PropertyInfo)memberExp.Member); var cMember = new CacheMember("", (PropertyInfo)rootMember); if (!string.IsNullOrEmpty(key)) { cMember.SetKey(key); } Convertors.Add(cMember.Key, accessor); Members[cMember.Key] = cMember; var newRule = new CacheMapRule <T>(this, cMember, fetcher); return(newRule); }
public void AddDeserializer(CacheMember cMember, Func <RedisValue, object> func) { CacheDeserializers[cMember.Key] = func; }
public void MergeBy(CacheMember member, Action <T, T> merger) { CacheMergers[member.Key] = merger; }
public CacheMapRule(CacheMap <T> cacheMap, CacheMember cMember, Expression <Func <T, RedisValue> > fetcher) { this._cacheMap = cacheMap; this.cMember = cMember; this.fetcher = fetcher; }