首页 > Windows开发 > 详细

C# 封装返回类

时间:2019-05-08 14:03:45      阅读:308      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

namespace TXR.Base
{
    public class CommonResult<TValue>
    {
        public CommonResult(TValue value)
        {
            this.Value = value;
        }

        public CommonResult(WarnResult value)
        {
            this.WarnResult = value;
        }

        [CompilerGenerated]
        public TValue Value { get; }

        [CompilerGenerated]
        public WarnResult WarnResult { get; }

        public static implicit operator CommonResult<TValue>(TValue value)
        {
            return new CommonResult<TValue>(value);
        }

        public static implicit operator CommonResult<TValue>(WarnResult value)
        {
            return new CommonResult<TValue>(value);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace TXR.Base
{
    public class WarnResult : ApiMessageErrorModel
    {
        public WarnResult(string msg)
        {
            base.Message = msg;
        }
    }
}

 第二版

using System.Runtime.CompilerServices;

namespace WordInsertImg
{
    public class CommonResult<TValue>
    {
        public CommonResult(TValue value)
        {
            this.Value = value;
        }

        public CommonResult(WarnResult value)
        {
            this.WarnResult = value;
        }

        [CompilerGenerated]
        public TValue Value { get; }

        [CompilerGenerated]
        public WarnResult WarnResult { get; }

        public static implicit operator CommonResult<TValue>(TValue value)
        {
            return new CommonResult<TValue>(value);
        }

        public static implicit operator CommonResult<TValue>(WarnResult value)
        {
            return new CommonResult<TValue>(value);
        }
    }

    public class WarnResult : ApiMessageErrorModel
    {
        public WarnResult(string msg)
        {
            base.Message = msg;
        }
    }
    public class ApiMessageErrorModel
    {
        public ApiMessageErrorModel()
        {
            this.Success = 0;
        }

        public ApiMessageErrorModel(string errorCode, string errorMsg)
        {
            this.Success = 0;
            this.Code = errorCode;
            this.Message = errorMsg;
        }
        public string Code { get; set; }
        public string Message { get; set; }
        public int Success { get; set; }

    }
}

 

C# 封装返回类

原文:https://www.cnblogs.com/blogs2014/p/10831262.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!