BResult.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:BResult
  3. * 作者:xulisong
  4. * 创建时间: 2019/7/29 17:54:09
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using MBIRevitBase.Result;
  13. namespace MBIRevitBase
  14. {
  15. /// <summary>
  16. /// bool类型结果
  17. /// </summary>
  18. public class BResult
  19. {
  20. public BResult(bool isSuccessed)
  21. {
  22. IsSuccessed = isSuccessed;
  23. }
  24. public BResult(bool isSuccessed, string message) : this(isSuccessed)
  25. {
  26. Message = message;
  27. }
  28. public bool IsSuccessed { get; private set; }
  29. public string Id { get; set; }
  30. public string Message { get; set; }
  31. /// <summary>
  32. /// tag
  33. /// </summary>
  34. public object Tag { get; set; }
  35. public static implicit operator bool(BResult result)
  36. {
  37. return result.IsSuccessed;
  38. }
  39. public static implicit operator BResult(bool d)
  40. {
  41. return new BResult(d);
  42. }
  43. public static implicit operator BResult(string errorMessage)
  44. {
  45. //有消息,则隐式转换成错误结果
  46. return new BResult(false, errorMessage);
  47. }
  48. public static implicit operator BResult(HttpResult result)
  49. {
  50. //有消息,则隐式转换成错误结果
  51. var rr = new BResult(true);
  52. if(result!=null)
  53. rr=new BResult(result.Result=="success",result.Message);
  54. return rr;
  55. }
  56. public override string ToString()
  57. {
  58. return Message ?? string.Empty;
  59. }
  60. }
  61. }