Infrastructure.UnifiedOutput
1.0.0
There is a newer version of this package available.
See the version list below for details.
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions 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.