LogikalResponse.cs 890 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using Newtonsoft.Json;
  4. namespace InABox.Integration.Logikal
  5. {
  6. public abstract class LogikalResponse : LogikalObject
  7. {
  8. public new abstract string ToString();
  9. public LogikalResponse Always(Action<LogikalResponse> handler)
  10. {
  11. handler?.Invoke(this);
  12. return this;
  13. }
  14. public LogikalResponse Error(Action<LogikalErrorResponse> handler, LogikalStatus status = LogikalStatus.IsError)
  15. {
  16. if (this is LogikalErrorResponse error && status.HasFlag(error.Status))
  17. handler?.Invoke(error);
  18. return this;
  19. }
  20. public LogikalResponse Success<T>(Action<T> handler) where T : LogikalResponse
  21. {
  22. if (this is T response)
  23. handler?.Invoke(response);
  24. return this;
  25. }
  26. }
  27. }