Пример #1
0
 public Action <T, T> GetMerger(CacheMember member)
 {
     if (CacheMergers.ContainsKey(member.Key))
     {
         return(CacheMergers[member.Key]);
     }
     else
     {
         return(null);
     }
 }
Пример #2
0
        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);
        }
Пример #3
0
 public void AddDeserializer(CacheMember cMember, Func <RedisValue, object> func)
 {
     CacheDeserializers[cMember.Key] = func;
 }
Пример #4
0
 public void MergeBy(CacheMember member, Action <T, T> merger)
 {
     CacheMergers[member.Key] = merger;
 }
Пример #5
0
 public CacheMapRule(CacheMap <T> cacheMap, CacheMember cMember, Expression <Func <T, RedisValue> > fetcher)
 {
     this._cacheMap = cacheMap;
     this.cMember   = cMember;
     this.fetcher   = fetcher;
 }