123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- namespace Safeguard.Dtos
- {
- public enum CodeEnum
- {
- Success,
- Fail,
- Error
- }
- public class ResultDto
- {
- public ResultDto(CodeEnum? code, string? message)
- {
- Code = code;
- Message = message;
- }
- public CodeEnum? Code { get; set; }
- public string? Message { get; set; }
- public static ResultDto Success()
- {
- return new ResultDto(CodeEnum.Success, "Ok!");
- }
- public static ResultDto Fail(string message)
- {
- return new ResultDto(CodeEnum.Fail, message);
- }
- public static ResultDto Error(string error)
- {
- return new ResultDto(CodeEnum.Error, error);
- }
- }
- public class ResultDto<T> : ResultDto
- {
- public ResultDto(CodeEnum code, string? message)
- : base(code, message)
- {
- }
- public ResultDto(CodeEnum code, string? message, T? data)
- : base(code, message)
- {
- Data = data;
- }
- public T? Data { get; set; }
- public static new ResultDto<T> Success()
- {
- return new ResultDto<T>(CodeEnum.Success, "Ok!");
- }
- public static ResultDto<T> Success(T data)
- {
- return new ResultDto<T>(CodeEnum.Success, "Ok!", data);
- }
- public static new ResultDto<T> Fail(string message)
- {
- return new ResultDto<T>(CodeEnum.Fail, message);
- }
- public static new ResultDto<T> Error(string message)
- {
- return new ResultDto<T>(CodeEnum.Error, message);
- }
- }
- }
|