Exemple #1
0
        public static IEnumerable <T> WhileOk <T>(this IEnumerable <T> collection)
        {
            foreach (var item in collection)
            {
                if (CancellationTokenExtensions.GetCancellationToken().IsCancellationRequested)
                {
                    break;
                }

                yield return(item);
            }
        }
Exemple #2
0
 public static TResult Maybe <T, TResult>(this T obj, Func <T, TResult> rewriter, TResult defaultValue = default(TResult))
 {
     CancellationTokenExtensions.ThrowOnCancellation();
     if (obj == null)
     {
         return(defaultValue);
     }
     else
     {
         return(rewriter(obj));
     }
 }
Exemple #3
0
 public static T As <T>(this object obj) where T : class
 {
     CancellationTokenExtensions.ThrowOnCancellation();
     return(obj as T);
 }
Exemple #4
0
 public static bool In <T>(this T obj, params T[] collection)
 {
     CancellationTokenExtensions.ThrowOnCancellation();
     return(collection.Contains(obj));
 }
Exemple #5
0
 public static T Unless <T>(this T obj, Predicate <T> condition) where T : class
 {
     CancellationTokenExtensions.ThrowOnCancellation();
     return(condition(obj) ? null : obj);
 }
Exemple #6
0
 public static T If <T>(this T obj, bool condition, Func <T, T> rewriter)
 {
     CancellationTokenExtensions.ThrowOnCancellation();
     return(condition ? rewriter(obj) : obj);
 }
Exemple #7
0
 public static T F <T>(this T obj, Action <T> rewriter)
 {
     CancellationTokenExtensions.ThrowOnCancellation();
     rewriter(obj);
     return(obj);
 }
Exemple #8
0
 public static TResult F <T, TResult>(this T obj, Func <T, TResult> rewriter)
 {
     CancellationTokenExtensions.ThrowOnCancellation();
     return(rewriter(obj));
 }