ResultMessage.cs 1.9 KB

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