Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. namespace SmalltalkBooleanExtensionMethods
  3. {
  4.  
  5.  
  6.         public static class BooleanExtension
  7.         {
  8.             public delegate Object ClosureWithNoExtraArgs ();
  9.             public delegate void ActionClosureWithNoExtraArgs ();
  10.  
  11.             public static Object ifTrue (this bool aBoolen, ClosureWithNoExtraArgs method)
  12.             {
  13.                 if (aBoolen)
  14.                     return method.DynamicInvoke ();
  15.                 else
  16.                     return null;
  17.             }
  18.  
  19.             public static Object ifTrue (this bool aBoolen, ActionClosureWithNoExtraArgs method)
  20.             {
  21.                 if (aBoolen)
  22.                     return method.DynamicInvoke ();
  23.                 else
  24.                     return null;
  25.             }
  26.  
  27.  
  28.             public static Object ifFalse (this bool aBoolen, ClosureWithNoExtraArgs method)
  29.             {
  30.                 if (aBoolen)
  31.                     return method.DynamicInvoke ();
  32.                 else
  33.                     return null;
  34.             }
  35.  
  36.             public static Object ifFalse (this bool aBoolen, ActionClosureWithNoExtraArgs method)
  37.             {
  38.                 if (aBoolen)
  39.                     return method.DynamicInvoke ();
  40.                 else
  41.                     return null;
  42.             }
  43.  
  44.  
  45.             public static Object ifTrueifFalse (this Boolean aBoolen, ClosureWithNoExtraArgs methodA, ClosureWithNoExtraArgs methodB)
  46.             {
  47.                 if (aBoolen)
  48.                     return methodA.DynamicInvoke ();
  49.                 else
  50.                     return methodB.DynamicInvoke ();
  51.             }
  52.  
  53.             public static Object ifTrueifFalse (this Boolean aBoolen, ActionClosureWithNoExtraArgs methodA, ActionClosureWithNoExtraArgs methodB)
  54.             {
  55.                 if (aBoolen)
  56.                     return methodA.DynamicInvoke ();
  57.                 else
  58.                     return methodB.DynamicInvoke ();
  59.             }
  60.            
  61.         }
  62.    
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement