Пример #1
0
        /// <summary>
        /// 获取key
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns></returns>
        private string GetKey(IInvocation invocation)
        {
            var sb       = new StringBuilder();
            var attrKeys = invocation.MethodInvocationTarget.GetCustomAttributes(typeof(TdbCacheKeyAttribute), true).Select(m => m as TdbCacheKeyAttribute);

            foreach (var attrKey in attrKeys)
            {
                //获取参数值
                var param = invocation.GetArgumentValue(attrKey.ParamIndex);

                //直接获取
                if (string.IsNullOrWhiteSpace(attrKey.FromPropertyName))
                {
                    sb.Append(this.ToStr(param));
                }
                //从属性获取
                else
                {
                    ///属性不存在
                    if (CommHelper.IsExistProperty(param, attrKey.FromPropertyName) == false)
                    {
                        throw new TdbException($"[缓存拦截器]找不到属性:{param.GetType().Name}.{attrKey.FromPropertyName}");
                    }

                    var paramValue = CommHelper.ReflectGet(param, attrKey.FromPropertyName);
                    sb.Append(this.ToStr(paramValue));
                }
            }

            return(sb.ToString());
        }
Пример #2
0
        public string ReflectGetSet(string name)
        {
            var model = new Model();

            CommHelper.ReflectSet(model, "Name", name);

            return(CommHelper.ReflectGet(model, "Name") as string);
        }