Skip to content

Commit

Permalink
Merge pull request #214 from Kysluss/136-add-xml-documentation
Browse files Browse the repository at this point in the history
136 add xml documentation
  • Loading branch information
altmann authored Jul 29, 2024
2 parents ae90e0b + 245339c commit 0c3376f
Show file tree
Hide file tree
Showing 18 changed files with 406 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/FluentResults/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// ReSharper disable once CheckNamespace
namespace FluentResults
{
/// <summary>
/// Helpful extensions for IEnumerable
/// </summary>
public static class EnumerableExtensions
{
/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions src/FluentResults/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
// ReSharper disable once CheckNamespace
namespace FluentResults
{
/// <summary>
/// Extension methods for object base type
/// </summary>
public static class ObjectExtensions
{
/// <summary>
/// Convert value to result
/// </summary>
/// <typeparam name="TValue">The type of the result's <see cref="Result{TValue}.Value"/></typeparam>
/// <param name="value">The value of the result</param>
public static Result<TValue> ToResult<TValue>(this TValue value)
{
return new Result<TValue>()
Expand Down
191 changes: 186 additions & 5 deletions src/FluentResults/Extensions/ResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,146 +3,327 @@

namespace FluentResults.Extensions
{
/// <summary>
/// Extension methods for Result
/// </summary>
public static class ResultExtensions
{
/// <summary>
/// Map all errors of the result via errorMapper
/// </summary>
/// <param name="resultTask">The current result</param>
/// <param name="errorMapper">Function to transform the errors</param>
public static async Task<Result> MapErrors(this Task<Result> resultTask, Func<IError, IError> errorMapper)
{
var result = await resultTask;
return result.MapErrors(errorMapper);
}

/// <summary>
/// Map all errors of the result via errorMapper
/// </summary>
/// <param name="resultTask">The current result</param>
/// <param name="errorMapper">Function to transform the errors</param>
public static async ValueTask<Result> MapErrors(this ValueTask<Result> resultTask, Func<IError, IError> errorMapper)
{
var result = await resultTask;
return result.MapErrors(errorMapper);
}

/// <summary>
/// Map all errors of the result via errorMapper
/// </summary>
/// <param name="resultTask">The current result</param>
/// <param name="errorMapper">Function to transform the errors</param>
public static async Task<Result<T>> MapErrors<T>(this Task<Result<T>> resultTask, Func<IError, IError> errorMapper)
{
var result = await resultTask;
return result.MapErrors(errorMapper);
}

/// <summary>
/// Map all errors of the result via errorMapper
/// </summary>
/// <param name="resultTask">The current result</param>
/// <param name="errorMapper">Function to transform the errors</param>
public static async ValueTask<Result<T>> MapErrors<T>(this ValueTask<Result<T>> resultTask, Func<IError, IError> errorMapper)
{
var result = await resultTask;
return result.MapErrors(errorMapper);
}

/// <summary>
/// Map all successes of the result via successMapper
/// </summary>
/// <param name="resultTask">The current result</param>
/// <param name="errorMapper">Function to transform the successes</param>
public static async Task<Result> MapSuccesses(this Task<Result> resultTask, Func<ISuccess, ISuccess> errorMapper)
{
var result = await resultTask;
return result.MapSuccesses(errorMapper);
}

/// <summary>
/// Map all successes of the result via successMapper
/// </summary>
/// <param name="resultTask">The current result</param>
/// <param name="errorMapper">Function to transform the successes</param>
public static async ValueTask<Result> MapSuccesses(this ValueTask<Result> resultTask, Func<ISuccess, ISuccess> errorMapper)
{
var result = await resultTask;
return result.MapSuccesses(errorMapper);
}

/// <summary>
/// Map all successes of the result via successMapper
/// <param name="resultTask">The current result</param>
/// <param name="errorMapper">Function to transform the successes</param>
/// </summary>
public static async Task<Result<T>> MapSuccesses<T>(this Task<Result<T>> resultTask, Func<ISuccess, ISuccess> errorMapper)
{
var result = await resultTask;
return result.MapSuccesses(errorMapper);
}

/// <summary>
/// Map all successes of the result via successMapper
/// </summary>
/// <param name="resultTask">The current result</param>
/// <param name="errorMapper">Function to transform the successes</param>
public static async ValueTask<Result<T>> MapSuccesses<T>(this ValueTask<Result<T>> resultTask, Func<ISuccess, ISuccess> errorMapper)
{
var result = await resultTask;
return result.MapSuccesses(errorMapper);
}

/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>
public static async Task<Result<TNew>> Bind<TOld, TNew>(this Task<Result<TOld>> resultTask, Func<TOld, Task<Result<TNew>>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}


/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>
public static async ValueTask<Result<TNew>> Bind<TOld, TNew>(this ValueTask<Result<TOld>> resultTask, Func<TOld, ValueTask<Result<TNew>>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}

/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>
public static async Task<Result<TNew>> Bind<TOld, TNew>(this Task<Result<TOld>> resultTask, Func<TOld, Result<TNew>> bind)
{
var result = await resultTask;
return result.Bind(bind);
}
/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>

public static async ValueTask<Result<TNew>> Bind<TOld, TNew>(this ValueTask<Result<TOld>> resultTask, Func<TOld, Result<TNew>> bind)
{
var result = await resultTask;
return result.Bind(bind);
}

/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>
public static async Task<Result> Bind<TOld>(this Task<Result<TOld>> resultTask, Func<TOld, Task<Result>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}

/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>
public static async Task<Result> Bind<TOld>(this Task<Result<TOld>> resultTask, Func<TOld, Result> bind)
{
var result = await resultTask;
return result.Bind(bind);
}

/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>
public static async ValueTask<Result> Bind<TOld>(this ValueTask<Result<TOld>> resultTask, Func<TOld, Result> bind)
{
var result = await resultTask;
return result.Bind(bind);
}

/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>
public static async ValueTask<Result> Bind<TOld>(this ValueTask<Result<TOld>> resultTask, Func<TOld, ValueTask<Result>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}


/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>
public static async Task<Result<TNew>> Bind<TNew>(this Task<Result> resultTask, Func<Task<Result<TNew>>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}


/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>
public static async ValueTask<Result<TNew>> Bind<TNew>(this ValueTask<Result> resultTask, Func<ValueTask<Result<TNew>>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}


/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>
public static async Task<Result> Bind(this Task<Result> resultTask, Func<Task<Result>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}


/// <summary>
/// Convert result with value to result with another value that may fail asynchronously.
/// </summary>
/// <example>
/// <code>
/// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
/// </code>
/// </example>
/// <param name="resultTask">The current result</param>
/// <param name="bind">Transformation that may fail.</param>
public static async ValueTask<Result> Bind(this ValueTask<Result> resultTask, Func<ValueTask<Result>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}

/// <summary>
/// Convert result with value to result with another value. Use valueConverter parameter to specify the value transformation logic.
/// </summary>
public static async Task<Result<TNewValue>> Map<TOldValue, TNewValue>(this Task<Result<TOldValue>> resultTask, Func<TOldValue, TNewValue> valueConverter)
{
var result = await resultTask;
return result.Map(valueConverter);
}

/// <summary>
/// Convert result with value to result with another value. Use valueConverter parameter to specify the value transformation logic.
/// </summary>
public static async Task<Result<TNewValue>> Map<TOldValue, TNewValue>(this ValueTask<Result<TOldValue>> resultTask, Func<TOldValue, TNewValue> valueConverter)
{
var result = await resultTask;
return result.Map(valueConverter);
}

/// <summary>
/// Convert result without value to a result containing a value
/// </summary>
/// <typeparam name="TValue">Type of the value</typeparam>
/// <param name="resultTask">The current result</param>
/// <param name="value">Value to add to the new result</param>
public static async Task<Result<TValue>> ToResult<TValue>(this Task<Result> resultTask, TValue value)
{
var result = await resultTask;
return result.ToResult(value);
}

/// <summary>
/// Convert result without value to a result containing a value
/// </summary>
/// <typeparam name="TValue">Type of the value</typeparam>
/// <param name="resultTask">The current result</param>
/// <param name="value">Value to add to the new result</param>
public static async Task<Result<TValue>> ToResult<TValue>(this ValueTask<Result> resultTask, TValue value)
{
var result = await resultTask;
Expand Down
5 changes: 5 additions & 0 deletions src/FluentResults/Logging/DefaultLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@

namespace FluentResults
{
/// <summary>
/// Default implementation of <see cref="IResultLogger"/> that doesn't log anything
/// </summary>
public class DefaultLogger : IResultLogger
{
/// <inheritdoc/>
public void Log(string context, string content, ResultBase result, LogLevel logLevel)
{

}

/// <inheritdoc/>
public void Log<TContext>(string content, ResultBase result, LogLevel logLevel)
{

Expand Down
Loading

0 comments on commit 0c3376f

Please sign in to comment.