Esempio n. 1
0
 /// <summary>
 /// Potentially runs an action taking the potential value's value.
 /// No effect if the potential value is no value.
 /// Returns an IMayHaveValue that has a value iff the action was run.
 /// </summary>
 public static IMayHaveValue IfHasValueThenDo <T>(this May <T> potentialValue, Action <T> hasValueAction)
 {
     if (hasValueAction == null)
     {
         throw new ArgumentNullException("hasValueAction");
     }
     return(potentialValue.Select(e => {
         hasValueAction(e);
         return 0;
     }));
 }
Esempio n. 2
0
 ///<summary>Returns the value contained in the given potential value as a nullable type, returning null if there is no contained value.</summary>
 public static T?AsNullable <T>(this May <T> potentialValue) where T : struct
 {
     return(potentialValue.Select(e => (T?)e).ElseDefault());
 }