Guest User

Untitled

a guest
Jul 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. /// <summary>
  2. /// Used to provide conditions before running other sub behaviors
  3. /// </summary>
  4. public abstract class Decorator : Behavior
  5. {
  6. private readonly Behavior _decorated;
  7.  
  8. protected Decorator(Behavior decorated)
  9. {
  10. _decorated = decorated;
  11. }
  12.  
  13. /// <summary>
  14. /// Condition used to check if it's possible to run this Behavior
  15. /// </summary>
  16. /// <param name="context"></param>
  17. /// <returns></returns>
  18. public abstract bool CanRun(object context);
  19.  
  20. protected override IEnumerable<RunStatus> Execute(object context)
  21. {
  22. if (!CanRun(context))
  23. yield return RunStatus.Failed;
  24. else
  25. foreach (var status in _decorated.Execute(context))
  26. yield return status
  27. }
  28. }
Add Comment
Please, Sign In to add comment