Infrastructure.UnifiedOutput 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Infrastructure.UnifiedOutput --version 1.0.0                
NuGet\Install-Package Infrastructure.UnifiedOutput -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Infrastructure.UnifiedOutput" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Infrastructure.UnifiedOutput --version 1.0.0                
#r "nuget: Infrastructure.UnifiedOutput, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Infrastructure.UnifiedOutput as a Cake Addin
#addin nuget:?package=Infrastructure.UnifiedOutput&version=1.0.0

// Install Infrastructure.UnifiedOutput as a Cake Tool
#tool nuget:?package=Infrastructure.UnifiedOutput&version=1.0.0                

Infrastructure.UnifiedOutput

webapi 统一输出结果

输出结构定义

/// <summary>
/// 参照企业微信Api,任意接口输出的响应应继承此类
/// </summary>
public class ResultDto
{
    /// <summary>
    /// 实例化时默认就是成功的
    /// </summary>
    public int errcode { get; set; } = ResultConsts.DEFAULT_SUCCESS_CODE; // 0为成功(无错误)

    public string errmsg { get; set; }

    /// <summary>
    /// 服务端处理需要,不需要响应输出
    /// </summary>
    [JsonIgnore]
    public bool issuccess { get { return this.errcode == ResultConsts.DEFAULT_SUCCESS_CODE; } }
}

常用的结果处理,可以根据情况进行对应引用

public static class Result
{

    /// <summary>
    /// 一个有消息提示有数据的成功响应
    /// </summary>
    /// <typeparam name="TValue">响应结果继承ResultDto</typeparam>
    /// <param name="result">响应结果</param>
    /// <param name="message">响应结果要提示的消息</param>
    /// <returns></returns>
    public static ResultDto Ok<TValue>(TValue result, string message) where TValue : ResultDto
    {
        result.errmsg = message;
        return result;
    }

    /// <summary>
    /// 一个没有消息提示没有附带数据的成功响应
    /// </summary>
    /// <returns></returns>
    public static ResultDto Ok()
    {
        return new ResultDto();
    }

    /// <summary>
    /// 一个有消息提示没有数据的成功响应
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    public static ResultDto Ok(string message)
    {
        return new ResultDto() { errmsg = message };
    }

    /// <summary>
    /// 一个有消息提示有数据的失败响应
    /// </summary>
    /// <typeparam name="TValue">响应结果继承ResultDto</typeparam>
    /// <param name="message">响应结果要提示的消息</param>
    /// <param name="errorCode">错误代码,默认是 10 </param>
    /// <returns></returns>
    public static ResultDto Fail<TValue>(string message, int errorCode = ResultConsts.DEFAULT_FAIL_CODE) where TValue : ResultDto, new()
    {
        var result = new TValue();// default(TValue);
        result.errcode = errorCode;
        result.errmsg = message;
        return result;
    }

    /// <summary>
    /// 一个有消息提示没有数据的失败响应
    /// </summary>
    /// <param name="message">响应结果要提示的消息</param>
    /// <param name="errorCode">错误代码,默认是 10 </param>
    /// <returns></returns>
    public static ResultDto Fail(string message, int errorCode = ResultConsts.DEFAULT_FAIL_CODE)
    {
        return new ResultDto
        {
            errcode = errorCode,
            errmsg = message
        };
    }

    /// <summary>
    /// 一个提示内容是程序异常的失败响应
    /// </summary>
    /// <param name="ex">捕获的异常</param>
    /// <param name="errorCode">错误代码,默认是 10</param>
    /// <returns></returns>
    public static ResultDto Fail(Exception ex, int errorCode = ResultConsts.DEFAULT_FAIL_CODE)
    {
        return new ResultDto
        {
            errcode = errorCode,
            errmsg = ex.Message
        };
    }

    /// <summary>
    /// 一个根据bool判断是成功或失败的响应,响应包含提示,没有数据
    /// </summary>
    /// <param name="issuccess"></param>
    /// <param name="message"></param>
    /// <returns></returns>
    public static ResultDto IsOk(bool issuccess, string message)
    {
        return new ResultDto
        {
            errcode = issuccess ? ResultConsts.DEFAULT_SUCCESS_CODE : ResultConsts.DEFAULT_FAIL_CODE,
            errmsg = message
        };
    } 
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Infrastructure.UnifiedOutput:

Package Downloads
Infrastructure.AccessToken.Authorization

Package Description

Infrastructure.AccessToken.Domain

Package Description

Infrastructure.SharedAppsettings.Client

Package Description

Infrastructure.Utils.EncryptFilter

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.4 752 8/25/2022
1.1.3 384 8/24/2022
1.1.2 425 8/17/2022
1.1.1 380 8/16/2022
1.1.0 472 4/3/2022
1.0.4 444 3/19/2022
1.0.3 422 3/18/2022
1.0.2 430 3/18/2022
1.0.1 411 3/17/2022
1.0.0 419 3/16/2022