Advertisement
dmitryzenevich

CommonExtensions

Jul 14th, 2021
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.39 KB | None | 0 0
  1. using System;
  2.  
  3. public static class CommonExtensions
  4. {
  5.     public static T With<T>(this T self, Action<T> apply, Func<bool> when)
  6.     {
  7.         if (when())
  8.             apply?.Invoke(self);
  9.  
  10.         return self;
  11.     }
  12.  
  13.     public static T With<T>(this T self, Action<T> apply, bool when = true)
  14.     {
  15.         if (when)
  16.             apply?.Invoke(self);
  17.  
  18.         return self;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement