Example #1
0
        public static ResultMo <TResult> ConvertToResult <TPara, TResult>(this ResultMo <TPara> res,
                                                                          Func <TPara, TResult> func)
        {
            var ot = new ResultMo <TResult>
            {
                ret     = res.ret,
                msg     = res.msg,
                sys_ret = res.sys_ret
            };

            if (func != null && res.IsSuccess())
            {
                ot.data = func(res.data);
            }

            return(ot);
        }
Example #2
0
        /// <summary>
        ///   将结果实体转换成其他结果实体
        /// </summary>
        /// <typeparam name="TResult">输出对象</typeparam>
        /// <typeparam name="TPara"></typeparam>
        /// <returns>输出对象</returns>
        public static ResultMo <TResult> ConvertToResult <TPara, TResult>(this TPara res,
                                                                          Func <TPara, TResult> func)
            where TPara : ResultMo
        {
            var ot = new ResultMo <TResult>
            {
                ret = res.ret,
                msg = res.msg
            };

            if (func != null && res.IsSuccess())
            {
                ot.data = func(res);
            }

            return(ot);
        }
Example #3
0
        public static TResult ConvertToResultInherit <TPara, TResult>(this ResultMo <TPara> res,
                                                                      Func <TPara, TResult> func)
            where TResult : ResultMo, new()
        {
            var oRes = default(TResult);

            if (func != null)
            {
                oRes = func(res.data);
            }

            if (oRes != null)
            {
                return(oRes);
            }

            oRes = new TResult
            {
                ret     = res.ret,
                msg     = res.msg,
                sys_ret = res.sys_ret
            };
            return(oRes);
        }
Example #4
0
 public static TResult ConvertToResultInherit <TResult>(this ResultMo res)
     where TResult : ResultMo, new()
 {
     return(ConvertToResultInherit <ResultMo, TResult>(res, null));
 }
Example #5
0
        /// <summary>
        /// 处理结果转化
        /// </summary>
        /// <param name="res"></param>
        /// <param name="tPara"></param>
        /// <param name="func"></param>
        /// <param name="isNullCheck">是否检查参数 data 为空</param>
        /// <typeparam name="TRes"></typeparam>
        /// <typeparam name="TPara"></typeparam>
        /// <returns></returns>
        public static ResultMo <TRes> WithResult <TRes, TPara>(this ResultMo <TRes> res, ResultMo <TPara> tPara,
                                                               Func <TPara, TRes> func, bool isNullCheck = true)

        {
            WithResult(res, tPara.sys_ret, tPara.ret, tPara.msg);

            if (isNullCheck && tPara.data == null)
            {
                return(res);
            }

            res.data = func.Invoke(tPara.data);
            return(res);
        }
Example #6
0
 /// <summary>
 /// 处理结果转化
 /// </summary>
 /// <param name="res"></param>
 /// <param name="tPara"></param>
 /// <typeparam name="TRes"></typeparam>
 /// <returns></returns>
 public static TRes WithResult <TRes>(this TRes res, ResultMo tPara)
     where TRes : ResultMo
 {
     return(res.WithResult(tPara.sys_ret, tPara.ret, tPara.msg));
 }
Example #7
0
 public static ResultMo <TResult> ConvertToResult <TResult>(this ResultMo res)
 {
     return(ConvertToResult <ResultMo, TResult>(res, null));
 }
Example #8
0
 /// <summary>
 /// 是否是对应的结果类型
 /// </summary>
 /// <param name="res"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static bool IsResultType(this ResultMo res, ResultTypes type) =>
 res.ret == (int)type;
Example #9
0
 /// <summary>
 ///  是否是Success
 /// </summary>
 /// <param name="res"></param>
 /// <returns></returns>
 public static bool IsSuccess(this ResultMo res) =>
 res.ret == 0;