Advertisement
Guest User

Untitled

a guest
Feb 26th, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. public class CommandCondition
  2. {
  3.     private readonly Func<CommandContext, bool> condition;
  4.     private readonly Func<CommandContext, Task> action;
  5.  
  6.     public CommandCondition(Func<CommandContext, bool> condition, Func<CommandContext, Task> action)
  7.     {
  8.         this.condition = condition ?? throw new ArgumentNullException(nameof(condition));
  9.         this.action = action ?? throw new ArgumentNullException(nameof(action));
  10.     }
  11.  
  12.     public async Task<bool> ExecuteIfTrueAsync(CommandContext context)
  13.     {
  14.         if (condition(context))
  15.         {
  16.             await action(context);
  17.             return true;
  18.         }
  19.         return false;
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement