Infrastructure.UnifiedOutput
1.0.2
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.2
NuGet\Install-Package Infrastructure.UnifiedOutput -Version 1.0.2
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.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Infrastructure.UnifiedOutput --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Infrastructure.UnifiedOutput, 1.0.2"
#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.2 // Install Infrastructure.UnifiedOutput as a Cake Tool #tool nuget:?package=Infrastructure.UnifiedOutput&version=1.0.2
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.ToErrorCode(),
errmsg = message
};
}
/// <summary>
/// 一个根据bool判断是成功或失败的响应,响应包含提示和数据
/// </summary>
/// <typeparam name="TValue">响应结果继承ResultDto</typeparam>
/// <param name="result">响应结果</param>
/// <param name="message">响应结果要提示的消息</param>
/// <returns></returns>
public static ResultDto IsOk<TValue>(TValue result, bool issuccess, string message) where TValue : ResultDto
{
result.errcode = issuccess.ToErrorCode();
result.errmsg = message;
return result;
}
/// <summary>
/// 一个根据自身是否为空的转换响应
/// </summary>
/// <param name="dto"></param>
/// <param name="errorMessage"></param>
/// <returns></returns>
public static ResultDto IsOk<T>(T dto, string errorMessage = "记录不存在") where T : ResultDto
{
if (dto == null)
{
return Result.Fail(errorMessage);
}
else
{
return dto;
}
}
/// <summary>
/// 默认的成功/失败码
/// </summary>
/// <param name="issuccess"></param>
/// <returns></returns>
public static int ToErrorCode(this bool issuccess)
{
return issuccess ? ResultConsts.DEFAULT_SUCCESS_CODE : ResultConsts.DEFAULT_FAIL_CODE;
}
/// <summary>
/// 默认的成功/失败码
/// </summary>
/// <param name="issuccess"></param>
/// <returns></returns>
public static int ErrorCode(bool issuccess)
{
return issuccess.ToErrorCode();
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.1)
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.