Пример #1
0
        /// <summary>
        /// Adds the given <paramref name="binder"/> to this Try's call sequence.
        /// </summary>
        public AsyncTry <U> ThenAsync <U>(Func <Task <U> > binder)
        {
            TryThrowHelper.VerifyBinderNotNull(binder);

            var frame = new AsyncTryFrame(TryFrameType.Action, async x => await binder().ConfigureAwait(false), null);

            return(new AsyncTry <U>(Frames.Add(frame)));
        }
Пример #2
0
        /// <summary>
        /// Adds the given <paramref name="binder"/> to this Try's call-sequence.
        /// </summary>
        public Try <U> Then <U>(Func <T, U> binder)
        {
            TryThrowHelper.VerifyBinderNotNull(binder);

            var frame = new SyncTryFrame(TryFrameType.Action, x => binder((T)x), null);

            return(new Try <U>(Frames.Add(frame)));
        }
Пример #3
0
        /// <summary>
        /// Adds the given <paramref name="binder"/> to this Try's call sequence.
        /// </summary>
        public AsyncTry <U> Then <U>(Func <U> binder)
        {
            TryThrowHelper.VerifyBinderNotNull(binder);

            var frame = new AsyncTryFrame(TryFrameType.Action, async x => binder(), null);

            return(new AsyncTry <U>(Frames.Add(frame)));
        }
Пример #4
0
        /// <summary>
        /// Adds the given <paramref name="exceptionHandler"/> for exceptions assignable to type
        /// <typeparamref name="TException"/> to this Try's call sequence.
        /// </summary>
        public AsyncTry <T> CatchAsync <TException>(Func <TException, Task <T> > exceptionHandler) where TException : Exception
        {
            TryThrowHelper.VerifyExceptionHandlerNotNull(exceptionHandler);

            var clause = new AsyncCatchClause(
                async ex => await exceptionHandler((TException)ex).ConfigureAwait(false),
                typeof(TException));

            return(new AsyncTry <T>(Frames.Add(new AsyncTryFrame(TryFrameType.CatchClause, null, clause))));
        }
Пример #5
0
        /// <summary>
        /// Adds the given <paramref name="binder"/> to this Try's call-sequence.
        /// </summary>
        public AsyncTry <U> ThenAsync <U>(Func <T, Task <U> > binder)
        {
            TryThrowHelper.VerifyBinderNotNull(binder);

            var asyncFrames = Frames
                              .ToAsync()
                              .Add(new AsyncTryFrame(TryFrameType.Action, async x => await binder((T)x).ConfigureAwait(false), null));

            return(new AsyncTry <U>(asyncFrames));
        }
Пример #6
0
        /// <summary>
        /// Adds the given <paramref name="exceptionHandler"/> for exceptions assignable to type
        /// <typeparamref name="TException"/> to this Try's call sequence.
        /// </summary>
        public Try <T> Catch <TException>(Func <TException, T> exceptionHandler) where TException : Exception
        {
            TryThrowHelper.VerifyExceptionHandlerNotNull(exceptionHandler);

            var clause = new SyncCatchClause(
                ex => exceptionHandler((TException)ex),
                typeof(TException));

            return(new Try <T>(Frames.Add(new SyncTryFrame(TryFrameType.CatchClause, null, clause))));
        }
Пример #7
0
        /// <summary>
        /// Adds the given <paramref name="exceptionHandler"/> for exceptions assignable to type
        /// <paramref name="exceptionType"/> to this Try's call sequence.
        /// </summary>
        public AsyncTry <T> CatchAsync(Type exceptionType, Func <Exception, Task <T> > exceptionHandler)
        {
            TryThrowHelper.VerifyExceptionType(exceptionType);
            TryThrowHelper.VerifyExceptionHandlerNotNull(exceptionHandler);

            var clause = new AsyncCatchClause(
                async ex => await exceptionHandler(ex).ConfigureAwait(false),
                exceptionType);

            return(new AsyncTry <T>(Frames.Add(new AsyncTryFrame(TryFrameType.CatchClause, null, clause))));
        }
Пример #8
0
        /// <summary>
        /// Adds the given <paramref name="exceptionHandler"/> for exceptions assignable to type
        /// <paramref name="exceptionType"/> to this Try's call sequence.
        /// </summary>
        public AsyncTry <T> Catch(Type exceptionType, Func <Exception, T> exceptionHandler)
        {
            TryThrowHelper.VerifyExceptionType(exceptionType);
            TryThrowHelper.VerifyExceptionHandlerNotNull(exceptionHandler);

            var clause = new AsyncCatchClause(
                async ex => exceptionHandler(ex),
                exceptionType);

            return(new AsyncTry <T>(Frames.Add(new AsyncTryFrame(TryFrameType.CatchClause, null, clause))));
        }