/// <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()); }
/// <summary> /// 设置更新者字段值 /// </summary> /// <param name="model">表对象</param> /// <param name="oper">操作者信息</param> protected void SetUpdateFields <T>(T model, OperatorInfo oper) where T : class { //更新者 if (CommHelper.IsExistProperty(model, FieldName_Updater)) { CommHelper.EmitSet(model, FieldName_Updater, oper.LoginName); } //更新时间 if (CommHelper.IsExistProperty(model, FieldName_UpdateTime)) { CommHelper.EmitSet(model, FieldName_UpdateTime, DateTime.Now); } }