示例#1
0
        /// <summary>
        /// This is an async way to chain a "Finally" handling callback method onto the end of the method chain. You can think of this as being
        /// similar to a "finally" call in .Net. The "Finally" will always call the callback method parameter. The callback itself can
        /// be responsible for whether or not to pass along a success or fail. There are also overloads that will simply call the callback
        /// and return the current success/fail status.
        /// <para>
        /// For example: When there is an error and there is a way for the error to be corrected or an attempt to correct the error can be made. The Catch
        /// chained method can correct the error and then allow the method chain to continue in a successful manner.
        /// </para>
        /// <para>
        /// Another example is where the Catch method can log an error.
        /// </para>
        /// </summary>
        /// <param name="callback">Method to be called (no matter what).</param>
        public static async Task <FunqResult> FinallyAsync(this Task <FunqResult> thisAsync, Func <FunqResult, Task <FunqResult> > callback)
        {
            var @this = await thisAsync.ConfigureAwait(false);

            var result = @this.IsSuccessful
                ? await callback(FunqFactory.Ok(@this)).ConfigureAwait(false)
                : await callback(FunqFactory.Fail(@this.Message, @this)).ConfigureAwait(false);

            return(result);
        }
示例#2
0
        /// <summary>
        /// This is a way to chain a error handling callback method onto the end of the method chain. The "Catch" will always call the callback
        /// method parameter. The callback itself is responsible for whether or not to pass along a success or fail.
        ///
        /// <para>
        /// For example: When there is an error and there is a way for the error to be corrected or an attempt to correct the error can be made. The Catch
        /// chained method can correct the error and then allow the method chain to continue in a successful manner.
        /// </para>
        /// <para>
        /// Another example is where the Catch method can log an error.
        /// </para>
        /// </summary>
        /// <param name="callback">Method to be called (no matter what).</param>
        public static FunqResult Catch(this FunqResult @this, Func <FunqResult, FunqResult> callback)
        {
            if (@this.IsSuccessful)
            {
                return(FunqFactory.Ok(@this.Message));
            }
            var errorFunq = callback(@this);

            return(errorFunq);
        }
示例#3
0
        /// <summary>
        /// This is a way to chain a error handling callback method onto the end of the method chain. The "Catch" will always call the callback
        /// method parameter. The callback itself is responsible for whether or not to pass along a success or fail.
        ///
        /// <para>
        /// For example: When there is an error and there is a way for the error to be corrected or an attempt to correct the error can be made. The Catch
        /// chained method can correct the error and then allow the method chain to continue in a successful manner.
        /// </para>
        /// <para>
        /// Another example is where the Catch method can log an error.
        /// </para>
        /// </summary>
        /// <param name="callback">Method to be called (no matter what).</param>
        public static FunqResult Catch <TInput>(this FunqResult <TInput> @this, Func <FunqResult <TInput>, FunqResult> callback)
        {
            if (@this.IsSuccessful)
            {
                return(FunqFactory.Ok(@this.Message));
            }
            var funq = callback(@this);

            return(funq);
        }
示例#4
0
        /// <summary>
        /// This is an async way to chain a error handling callback method onto the end of the method chain. The "Catch" will always call the callback
        /// method parameter. The callback itself is responsible for whether or not to pass along a success or fail.
        /// <para>
        /// For example: When there is an error and there is a way for the error to be corrected or an attempt to correct the error can be made. The Catch
        /// chained method can correct the error and then allow the method chain to continue in a successful manner.
        /// </para>
        /// <para>
        /// Another example is where the Catch method can log an error.
        /// </para>
        /// </summary>
        /// <param name="callback">Method to be called (no matter what).</param>
        public static async Task <FunqResult> CatchAsync(this Task <FunqResult> thisTask, Func <Task <FunqResult> > callback)
        {
            var @this = await thisTask.ConfigureAwait(false);

            if (@this.IsSuccessful)
            {
                return(await Task.FromResult(FunqFactory.Ok(@this.Message)).ConfigureAwait(false));
            }
            var errorFunq = await callback().ConfigureAwait(false);

            return(errorFunq);
        }
示例#5
0
        /// <summary>
        /// This is a way to chain a "Finally" handling callback method onto the end of the method chain. You can think of this as being
        /// similar to a "finally" call in .Net. The "Finally" will always call the callback method parameter. The callback itself can
        /// be responsible for whether or not to pass along a success or fail. There are also overloads that will simply call the callback
        /// and return the current success/fail status.
        /// <para>
        /// For example: When there is an error and there is a way for the error to be corrected or an attempt to correct the error can be made. The Catch
        /// chained method can correct the error and then allow the method chain to continue in a successful manner.
        /// </para>
        /// <para>
        /// Another example is where the Catch method can log an error.
        /// </para>
        /// </summary>
        /// <param name="callback">Method to be called (no matter what).</param>
        public static FunqResult Finally(this FunqResult @this, Action <FunqResult> callback)
        {
            if (@this.IsSuccessful)
            {
                var okResult = FunqFactory.Ok(@this, @this.Message);
                callback(okResult);
                return(okResult);
            }
            var failResult = FunqFactory.Fail(@this.Message);

            callback(failResult);
            return(failResult);
        }
示例#6
0
        /// <summary>
        /// This is an async way to chain a "Finally" handling callback method onto the end of the method chain. You can think of this as being
        /// similar to a "finally" call in .Net. The "Finally" will always call the callback method parameter. The callback itself can
        /// be responsible for whether or not to pass along a success or fail. There are also overloads that will simply call the callback
        /// and return the current success/fail status.
        /// <para>
        /// For example: When there is an error and there is a way for the error to be corrected or an attempt to correct the error can be made. The Catch
        /// chained method can correct the error and then allow the method chain to continue in a successful manner.
        /// </para>
        /// <para>
        /// Another example is where the Catch method can log an error.
        /// </para>
        /// </summary>
        /// <param name="callback">Method to be called (no matter what).</param>
        public static async Task <FunqResult> Finally(this Task <FunqResult> thisAsync, Func <FunqResult, Task> callback)
        {
            var @this = await thisAsync.ConfigureAwait(false);

            if (@this.IsSuccessful)
            {
                var okResult = FunqFactory.Ok(@this, @this.Message);
                await callback(okResult).ConfigureAwait(false);

                return(okResult);
            }
            var failResult = FunqFactory.Fail(@this.Message);

            await callback(failResult).ConfigureAwait(false);

            return(failResult);
        }
示例#7
0
        /// <summary>
        /// This is a way to chain a "Finally" handling callback method onto the end of the method chain. You can think of this as being
        /// similar to a "finally" call in .Net. The "Finally" will always call the callback method parameter. The callback itself can
        /// be responsible for whether or not to pass along a success or fail. There are also overloads that will simply call the callback
        /// and return the current success/fail status.
        /// <para>
        /// For example: When there is an error and there is a way for the error to be corrected or an attempt to correct the error can be made. The Catch
        /// chained method can correct the error and then allow the method chain to continue in a successful manner.
        /// </para>
        /// <para>
        /// Another example is where the Catch method can log an error.
        /// </para>
        /// </summary>
        /// <param name="callback">Method to be called (no matter what).</param>
        public static FunqResult Finally(this FunqResult @this, Func <FunqResult, FunqResult> callback)
        {
            var result = @this.IsSuccessful ? callback(FunqFactory.Ok(@this)) : callback(FunqFactory.Fail(@this.Message, @this));

            return(result);
        }
示例#8
0
        /// <summary>
        /// Converts the specified object to a <see cref="FunqResult{T}"/> in an async manner to allow for async operations
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="thisTask"></param>
        /// <returns></returns>
        public static async Task <FunqResult <T> > GetFunqyAsync <T>(this Task <T> thisTask)
        {
            var @this = await thisTask;

            return(await Task.FromResult(@this == null?FunqFactory.Fail <T>("Nothing to get Funqy with", null) : FunqFactory.Ok(@this))
                   .ConfigureAwait(false));
        }
示例#9
0
        /// <summary>
        /// This is a way to chain a "Finally" handling callback method onto the end of the method chain. You can think of this as being
        /// similar to a "finally" call in .Net. The "Finally" will always call the callback method parameter. The callback itself can
        /// be responsible for whether or not to pass along a success or fail. There are also overloads that will simply call the callback
        /// and return the current success/fail status.
        /// <para>
        /// For example: When there is an error and there is a way for the error to be corrected or an attempt to correct the error can be made. The Catch
        /// chained method can correct the error and then allow the method chain to continue in a successful manner.
        /// </para>
        /// <para>
        /// Another example is where the Catch method can log an error.
        /// </para>
        /// </summary>
        /// <param name="callback">Method to be called (no matter what).</param>
        public static FunqResult <TOutput> Finally <TInput, TOutput>(this FunqResult <TInput> @this, Func <FunqResult <TInput>, FunqResult <TOutput> > callback)
        {
            var result = @this.IsSuccessful ? callback(FunqFactory.Ok(@this, @this.Message)) : callback(FunqFactory.Fail(@this.Message, @this));

            return(result);
        }
示例#10
0
 /// <summary>
 /// Converts the specified object to a <see cref="FunqResult{T}"/>
 /// </summary>
 public static FunqResult <Guid> GetFunqy(this Guid @this)
 {
     return(@this == default(Guid)
         ? FunqFactory.Fail <Guid>("The Guid provided to get funqy was the default Guid value and invalid", null)
         : FunqFactory.Ok(@this));
 }
示例#11
0
 /// <summary>
 /// Converts the specified object to a <see cref="FunqResult{T}"/>
 /// </summary>
 public static FunqResult <T> GetFunqy <T>(this T @this)
 {
     return(@this == null?FunqFactory.Fail <T>("Nothing to get Funqy with", null) : FunqFactory.Ok(@this));
 }