ServiceResultMessage.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Bowin.Common.WebModels
  5. {
  6. public class ServiceResultMessage<T> : ServiceResultMessage
  7. {
  8. public new T Data { get; set; }
  9. }
  10. public class ServiceResultMessage
  11. {
  12. public bool IsSuccess { get; set; }
  13. public int Code { get; set; } = 0;
  14. public string Message { get; set; }
  15. public object Data { get; set; }
  16. public static ServiceResultMessage<T> Convert<T>(ServiceResultMessage error)
  17. {
  18. return new ServiceResultMessage<T> { IsSuccess = error.IsSuccess, Message = error.Message };
  19. }
  20. public static ServiceResultMessage GetError(string _message)
  21. {
  22. return new ServiceResultMessage { IsSuccess = false, Message = _message };
  23. }
  24. public static ServiceResultMessage<T> GetError<T>(string _message) where T : class
  25. {
  26. return Convert<T>(GetError(_message));
  27. }
  28. public static ServiceResultMessage GetError(int code, string _message)
  29. {
  30. return new ServiceResultMessage { Code = code, IsSuccess = false, Message = _message };
  31. }
  32. public static ServiceResultMessage<T> GetError<T>(int code, string _message)
  33. {
  34. return new ServiceResultMessage<T> { Code = code, IsSuccess = false, Message = _message };
  35. }
  36. public static ServiceResultMessage GetError(string _message, object _data)
  37. {
  38. return new ServiceResultMessage { IsSuccess = false, Message = _message, Data = _data };
  39. }
  40. public static ServiceResultMessage<T> GetError<T>(string _message, T _data) where T : class
  41. {
  42. return new ServiceResultMessage<T> { IsSuccess = false, Message = _message, Data = _data };
  43. }
  44. public static ServiceResultMessage Success()
  45. {
  46. return new ServiceResultMessage { IsSuccess = true, Message = "" };
  47. }
  48. public static ServiceResultMessage Success(object _data)
  49. {
  50. return new ServiceResultMessage { IsSuccess = true, Message = "", Data = _data };
  51. }
  52. public static ServiceResultMessage<T> Success<T>() where T : class
  53. {
  54. return Convert<T>(Success());
  55. }
  56. public static ServiceResultMessage<T> Success<T>(T _data) where T : class
  57. {
  58. return new ServiceResultMessage<T> { IsSuccess = true, Message = "", Data = _data };
  59. }
  60. }
  61. }