Example #1
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));
        }
Example #2
0
 /// <summary>
 /// Converts the specified object to a <see cref="FunqResult{T}"/> in an async manner to allow for async operations
 /// </summary>
 /// <param name="this"></param>
 /// <returns></returns>
 public static async Task <FunqResult <Guid> > GetFunqyAsync(this Guid @this)
 {
     return(await Task.FromResult(@this == default(Guid)
                                  ?FunqFactory.Fail <Guid>("The Guid provided to get funqy was the default Guid value and invalid", null)
                                  : FunqFactory.Ok(@this))
            .ConfigureAwait(false));
 }
        public static FunqResult Finally <TInput>(this FunqResult <TInput> @this, Func <FunqResult <TInput>, FunqResult> callback)
        {
            var result = @this.IsSuccessful
                ? callback(FunqFactory.KeepGroovin(@this, @this.Message))
                : callback(FunqFactory.Fail(@this.Message, @this));

            return(result);
        }
Example #4
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 <TOutput>(this FunqResult @this, Func <FunqResult, FunqResult <TOutput> > callback)
        {
            var result = @this.IsSuccessful
                ? callback(FunqFactory.Ok(@this.Message))
                : callback(FunqFactory.Fail(@this.Message));

            return(result);
        }
        public static async Task <FunqResult <TOutput> > FinallyAsync <TInput, TOutput>(this Task <FunqResult <TInput> > thisAsync, Func <FunqResult <TInput>, Task <FunqResult <TOutput> > > callback)
        {
            var @this = await thisAsync.ConfigureAwait(false);

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

            return(result);
        }
Example #6
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);
        }
Example #7
0
        /// <summary>
        /// Chains a method onto a <see cref="FunqResult{T}"/>.
        /// </summary>
        /// <param name="callback">Method to be used as long as <see cref="FunqResult.IsSuccessful"/> is true</param>
        public static FunqResult <TOutput> Then <TInput, TOutput>(this FunqResult <TInput> @this, Func <TInput, FunqResult <TOutput> > callback)
        {
            if (@this.IsFailure)
            {
                return(FunqFactory.Fail(@this.Message, default(TOutput)));
            }
            var result = callback(@this.Value);

            return(result);
        }
Example #8
0
        /// <summary>
        /// Chains a method onto a <see cref="FunqResult{T}"/>.
        /// </summary>
        /// <param name="callback">Method to be used as long as <see cref="FunqResult.IsSuccessful"/> is true</param>
        public static FunqResult <TOutput> Then <TOutput>(this FunqResult @this, Func <FunqResult <TOutput> > callback)
        {
            if (@this.IsFailure)
            {
                return(FunqFactory.Fail <TOutput>(@this.Message, null));
            }
            var funq = callback();

            return(funq);
        }
        public static FunqResult <TOutput> Catch <TOutput>(this FunqResult <TOutput> @this, Func <FunqResult <TOutput> > callback)
        {
            if (@this.IsSuccessful)
            {
                return(FunqFactory.KeepGroovin(@this.Result, @this.Message));
            }
            var errorFunq = callback();

            return(errorFunq);
        }
Example #10
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);
        }
Example #11
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);
        }
        public static async Task <FunqResult> CatchAsync <TInput>(this Task <FunqResult <TInput> > thisTask, Func <Task <FunqResult> > callback)
        {
            var @this = await thisTask.ConfigureAwait(false);

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

            return(funq);
        }
Example #13
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);
        }
Example #14
0
        /// <summary>
        /// Chains a method onto a <see cref="FunqResult{T}"/> in an async manner to allow for Async usage.
        /// </summary>
        /// <param name="callback">Method to be used as long as <see cref="FunqResult.IsSuccessful"/> is true</param>
        public static async Task <FunqResult> ThenAsync <TInput>(this Task <FunqResult <TInput> > thisTask, Func <TInput, Task <FunqResult> > callback)
        {
            var @this = await thisTask;

            if (@this.IsFailure)
            {
                return(await Task.FromResult(FunqFactory.Fail(@this.Message)).ConfigureAwait(false));
            }
            var funq = await callback(@this.Value).ConfigureAwait(false);

            return(funq);
        }
Example #15
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);
        }
Example #16
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);
        }
Example #17
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);
        }
Example #18
0
 /// <summary>
 /// Chains a method onto a <see cref="FunqResult{T}"/>.
 /// </summary>
 /// <param name="callback">Method to be used as long as <see cref="FunqResult.IsSuccessful"/> is true</param>
 public static FunqResult Then(this FunqResult @this, Func <FunqResult> callback)
 {
     return(@this.IsFailure ? FunqFactory.Fail(@this.Message) : callback());
 }
Example #19
0
 /// <summary>
 /// Chains a method onto a <see cref="FunqResult{T}"/>.
 /// </summary>
 /// <param name="callback">Method to be used as long as <see cref="FunqResult.IsSuccessful"/> is true</param>
 public static FunqResult Then <TInput>(this FunqResult <TInput> @this, Func <TInput, FunqResult> callback)
 {
     return(@this.IsFailure ? FunqFactory.Fail(@this.Message) : callback(@this.Value));
 }
 public static async Task <FunqResult <T> > GetFunqyAsync <T>(this T @this)
 {
     return(await Task.FromResult(@this == null?FunqFactory.Fail <T>("Nothing to get Funqy with", null) : FunqFactory.KeepGroovin(@this))
            .ConfigureAwait(false));
 }
Example #21
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));
 }
Example #22
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));
 }