BResult.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. namespace MBIRevitBase
  13. {
  14. /// <summary>
  15. /// bool类型结果
  16. /// </summary>
  17. public class BResult
  18. {
  19. public BResult(bool isSuccessed)
  20. {
  21. IsSuccessed = isSuccessed;
  22. }
  23. public BResult(bool isSuccessed, string message) : this(isSuccessed)
  24. {
  25. Message = message;
  26. }
  27. public bool IsSuccessed { get; private set; }
  28. public string Id { get; set; }
  29. public string Message { get; set; }
  30. /// <summary>
  31. /// tag
  32. /// </summary>
  33. public object Tag { get; set; }
  34. public static implicit operator bool(BResult result)
  35. {
  36. return result.IsSuccessed;
  37. }
  38. public static implicit operator BResult(bool d)
  39. {
  40. return new BResult(d);
  41. }
  42. public static implicit operator BResult(string errorMessage)
  43. {
  44. //有消息,则隐式转换成错误结果
  45. return new BResult(false, errorMessage);
  46. }
  47. public override string ToString()
  48. {
  49. return Message ?? string.Empty;
  50. }
  51. }
  52. }