当前位置:首页 > C#教程 > C#高级

C# 封装返回类

            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; }

        publicstaticimplicitoperator CommonResult<TValue>(TValue value)
        {
            returnnew CommonResult<TValue>(value);
        }

        publicstaticimplicitoperator CommonResult<TValue>(WarnResult value)
        {
            returnnew 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; }

        publicstaticimplicitoperator CommonResult<TValue>(TValue value)
        {
            returnnew CommonResult<TValue>(value);
        }

        publicstaticimplicitoperator CommonResult<TValue>(WarnResult value)
        {
            returnnew CommonResult<TValue>(value);
        }
    }

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

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

    }
}

 

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


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!