diff --git a/src/FluentResults/Extensions/EnumerableExtensions.cs b/src/FluentResults/Extensions/EnumerableExtensions.cs
index c041a7d..bd23435 100644
--- a/src/FluentResults/Extensions/EnumerableExtensions.cs
+++ b/src/FluentResults/Extensions/EnumerableExtensions.cs
@@ -3,6 +3,9 @@
// ReSharper disable once CheckNamespace
namespace FluentResults
{
+ ///
+ /// Helpful extensions for IEnumerable
+ ///
public static class EnumerableExtensions
{
///
diff --git a/src/FluentResults/Extensions/ObjectExtensions.cs b/src/FluentResults/Extensions/ObjectExtensions.cs
index 3fa3a48..0828b7a 100644
--- a/src/FluentResults/Extensions/ObjectExtensions.cs
+++ b/src/FluentResults/Extensions/ObjectExtensions.cs
@@ -1,8 +1,16 @@
// ReSharper disable once CheckNamespace
namespace FluentResults
{
+ ///
+ /// Extension methods for object base type
+ ///
public static class ObjectExtensions
{
+ ///
+ /// Convert value to result
+ ///
+ /// The type of the result's
+ /// The value of the result
public static Result ToResult(this TValue value)
{
return new Result()
diff --git a/src/FluentResults/Extensions/ResultExtensions.cs b/src/FluentResults/Extensions/ResultExtensions.cs
index f11dfbe..23ed08a 100644
--- a/src/FluentResults/Extensions/ResultExtensions.cs
+++ b/src/FluentResults/Extensions/ResultExtensions.cs
@@ -3,73 +3,156 @@
namespace FluentResults.Extensions
{
+ ///
+ /// Extension methods for Result
+ ///
public static class ResultExtensions
{
+ ///
+ /// Map all errors of the result via errorMapper
+ ///
+ /// The current result
+ /// Function to transform the errors
public static async Task MapErrors(this Task resultTask, Func errorMapper)
{
var result = await resultTask;
return result.MapErrors(errorMapper);
}
+ ///
+ /// Map all errors of the result via errorMapper
+ ///
+ /// The current result
+ /// Function to transform the errors
public static async ValueTask MapErrors(this ValueTask resultTask, Func errorMapper)
{
var result = await resultTask;
return result.MapErrors(errorMapper);
}
+ ///
+ /// Map all errors of the result via errorMapper
+ ///
+ /// The current result
+ /// Function to transform the errors
public static async Task> MapErrors(this Task> resultTask, Func errorMapper)
{
var result = await resultTask;
return result.MapErrors(errorMapper);
}
+ ///
+ /// Map all errors of the result via errorMapper
+ ///
+ /// The current result
+ /// Function to transform the errors
public static async ValueTask> MapErrors(this ValueTask> resultTask, Func errorMapper)
{
var result = await resultTask;
return result.MapErrors(errorMapper);
}
+ ///
+ /// Map all successes of the result via successMapper
+ ///
+ /// The current result
+ /// Function to transform the successes
public static async Task MapSuccesses(this Task resultTask, Func errorMapper)
{
var result = await resultTask;
return result.MapSuccesses(errorMapper);
}
+ ///
+ /// Map all successes of the result via successMapper
+ ///
+ /// The current result
+ /// Function to transform the successes
public static async ValueTask MapSuccesses(this ValueTask resultTask, Func errorMapper)
{
var result = await resultTask;
return result.MapSuccesses(errorMapper);
}
+ ///
+ /// Map all successes of the result via successMapper
+ /// The current result
+ /// Function to transform the successes
+ ///
public static async Task> MapSuccesses(this Task> resultTask, Func errorMapper)
{
var result = await resultTask;
return result.MapSuccesses(errorMapper);
}
+ ///
+ /// Map all successes of the result via successMapper
+ ///
+ /// The current result
+ /// Function to transform the successes
public static async ValueTask> MapSuccesses(this ValueTask> resultTask, Func errorMapper)
{
var result = await resultTask;
return result.MapSuccesses(errorMapper);
}
+ ///
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async Task> Bind(this Task> resultTask, Func>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}
-
+
+ ///
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async ValueTask> Bind(this ValueTask> resultTask, Func>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}
+ ///
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async Task> Bind(this Task> resultTask, Func> bind)
{
var result = await resultTask;
return result.Bind(bind);
}
+ ///
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async ValueTask> Bind(this ValueTask> resultTask, Func> bind)
{
@@ -77,72 +160,170 @@ public static async ValueTask> Bind(this ValueTask
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async Task Bind(this Task> resultTask, Func> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}
+ ///
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async Task Bind(this Task> resultTask, Func bind)
{
var result = await resultTask;
return result.Bind(bind);
}
+ ///
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async ValueTask Bind(this ValueTask> resultTask, Func bind)
{
var result = await resultTask;
return result.Bind(bind);
}
+ ///
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async ValueTask Bind(this ValueTask> resultTask, Func> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}
-
+
+ ///
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async Task> Bind(this Task resultTask, Func>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}
-
+
+ ///
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async ValueTask> Bind(this ValueTask resultTask, Func>> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}
-
+
+ ///
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async Task Bind(this Task resultTask, Func> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}
-
+
+ ///
+ /// Convert result with value to result with another value that may fail asynchronously.
+ ///
+ ///
+ ///
+ /// var bakeryDtoResult = await result.Bind(GetWhichMayFail);
+ ///
+ ///
+ /// The current result
+ /// Transformation that may fail.
public static async ValueTask Bind(this ValueTask resultTask, Func> bind)
{
var result = await resultTask;
return await result.Bind(bind);
}
+ ///
+ /// Convert result with value to result with another value. Use valueConverter parameter to specify the value transformation logic.
+ ///
public static async Task> Map(this Task> resultTask, Func valueConverter)
{
var result = await resultTask;
return result.Map(valueConverter);
}
+ ///
+ /// Convert result with value to result with another value. Use valueConverter parameter to specify the value transformation logic.
+ ///
public static async Task> Map(this ValueTask> resultTask, Func valueConverter)
{
var result = await resultTask;
return result.Map(valueConverter);
}
+ ///
+ /// Convert result without value to a result containing a value
+ ///
+ /// Type of the value
+ /// The current result
+ /// Value to add to the new result
public static async Task> ToResult(this Task resultTask, TValue value)
{
var result = await resultTask;
return result.ToResult(value);
}
+ ///
+ /// Convert result without value to a result containing a value
+ ///
+ /// Type of the value
+ /// The current result
+ /// Value to add to the new result
public static async Task> ToResult(this ValueTask resultTask, TValue value)
{
var result = await resultTask;
diff --git a/src/FluentResults/Logging/DefaultLogger.cs b/src/FluentResults/Logging/DefaultLogger.cs
index 14c3bde..b149a2e 100644
--- a/src/FluentResults/Logging/DefaultLogger.cs
+++ b/src/FluentResults/Logging/DefaultLogger.cs
@@ -4,13 +4,18 @@
namespace FluentResults
{
+ ///
+ /// Default implementation of that doesn't log anything
+ ///
public class DefaultLogger : IResultLogger
{
+ ///
public void Log(string context, string content, ResultBase result, LogLevel logLevel)
{
}
+ ///
public void Log(string content, ResultBase result, LogLevel logLevel)
{
diff --git a/src/FluentResults/Logging/IResultLogger.cs b/src/FluentResults/Logging/IResultLogger.cs
index 377ecf6..b6f3a21 100644
--- a/src/FluentResults/Logging/IResultLogger.cs
+++ b/src/FluentResults/Logging/IResultLogger.cs
@@ -4,9 +4,27 @@
namespace FluentResults
{
+ ///
+ /// Logging interface. Implement this if you want to have custom logging of results
+ ///
public interface IResultLogger
{
+ ///
+ /// Log result information
+ ///
+ /// Additional log context
+ /// Content to log
+ /// The result to log
+ /// The
void Log(string context, string content, ResultBase result, LogLevel logLevel);
+
+ ///
+ /// Log result information
+ ///
+ /// Additional log context
+ /// Content to log
+ /// The result to log
+ /// The
void Log(string content, ResultBase result, LogLevel logLevel);
}
}
\ No newline at end of file
diff --git a/src/FluentResults/Reasons/Error.cs b/src/FluentResults/Reasons/Error.cs
index faca157..98d3294 100644
--- a/src/FluentResults/Reasons/Error.cs
+++ b/src/FluentResults/Reasons/Error.cs
@@ -25,6 +25,9 @@ public class Error : IError
///
public List Reasons { get; }
+ ///
+ /// Creates a new instance of
+ ///
protected Error()
{
Metadata = new Dictionary();
@@ -146,6 +149,9 @@ public Error WithMetadata(Dictionary metadata)
return this;
}
+ ///
+ /// ToString override
+ ///
public override string ToString()
{
return new ReasonStringBuilder()
diff --git a/src/FluentResults/Reasons/ExceptionalError.cs b/src/FluentResults/Reasons/ExceptionalError.cs
index 3db4e14..dd63174 100644
--- a/src/FluentResults/Reasons/ExceptionalError.cs
+++ b/src/FluentResults/Reasons/ExceptionalError.cs
@@ -13,16 +13,29 @@ public class ExceptionalError : Error, IExceptionalError
///
public Exception Exception { get; }
+
+ ///
+ /// Initialize a new instance with an exception
+ ///
+ /// The exception
public ExceptionalError(Exception exception)
: this(exception.Message, exception)
{ }
+ ///
+ /// Initialize a new instance with a custom message and an exception
+ ///
+ /// The message
+ /// The exception
public ExceptionalError(string message, Exception exception)
: base(message)
{
Exception = exception;
}
+ ///
+ /// ToString override
+ ///
public override string ToString()
{
return new ReasonStringBuilder()
diff --git a/src/FluentResults/Reasons/IError.cs b/src/FluentResults/Reasons/IError.cs
index 958205c..e77cf1f 100644
--- a/src/FluentResults/Reasons/IError.cs
+++ b/src/FluentResults/Reasons/IError.cs
@@ -3,6 +3,9 @@
// ReSharper disable once CheckNamespace
namespace FluentResults
{
+ ///
+ /// Definition of an error
+ ///
public interface IError : IReason
{
///
diff --git a/src/FluentResults/Reasons/IExceptionalError.cs b/src/FluentResults/Reasons/IExceptionalError.cs
index 1a9a032..e46e946 100644
--- a/src/FluentResults/Reasons/IExceptionalError.cs
+++ b/src/FluentResults/Reasons/IExceptionalError.cs
@@ -3,8 +3,14 @@
// ReSharper disable once CheckNamespace
namespace FluentResults
{
+ ///
+ /// Definition of an error containing an exception
+ ///
public interface IExceptionalError : IError
{
+ ///
+ /// The exception
+ ///
Exception Exception { get; }
}
diff --git a/src/FluentResults/Reasons/IReason.cs b/src/FluentResults/Reasons/IReason.cs
index 2f033a6..9759e7e 100644
--- a/src/FluentResults/Reasons/IReason.cs
+++ b/src/FluentResults/Reasons/IReason.cs
@@ -3,10 +3,19 @@
// ReSharper disable once CheckNamespace
namespace FluentResults
{
+ ///
+ /// Definition of a reason. This is also the base of ISuccess and IError
+ ///
public interface IReason
{
+ ///
+ /// The reason's message
+ ///
string Message { get; }
+ ///
+ /// Any metadata added to the reason
+ ///
Dictionary Metadata { get; }
}
}
\ No newline at end of file
diff --git a/src/FluentResults/Reasons/ISuccess.cs b/src/FluentResults/Reasons/ISuccess.cs
index d7ad314..437616b 100644
--- a/src/FluentResults/Reasons/ISuccess.cs
+++ b/src/FluentResults/Reasons/ISuccess.cs
@@ -1,6 +1,9 @@
// ReSharper disable once CheckNamespace
namespace FluentResults
{
+ ///
+ /// Definition of a success
+ ///
public interface ISuccess : IReason
{ }
}
\ No newline at end of file
diff --git a/src/FluentResults/Reasons/ReasonExtensions.cs b/src/FluentResults/Reasons/ReasonExtensions.cs
index 8494b0f..f13d5db 100644
--- a/src/FluentResults/Reasons/ReasonExtensions.cs
+++ b/src/FluentResults/Reasons/ReasonExtensions.cs
@@ -3,8 +3,18 @@
// ReSharper disable once CheckNamespace
namespace FluentResults
{
+ ///
+ /// Extensions for
+ ///
public static class ReasonExtensions
{
+ ///
+ /// Check if a metadata key exists
+ ///
+ /// The reason instance
+ /// The metadata key
+ /// True if the metadata key exists
+ ///
public static bool HasMetadataKey(this IReason reason, string key)
{
if(string.IsNullOrEmpty(key))
@@ -13,6 +23,14 @@ public static bool HasMetadataKey(this IReason reason, string key)
return reason.Metadata.ContainsKey(key);
}
+ ///
+ /// Check if a metadata key exists and matches the supplied predicate
+ ///
+ /// The reason instance
+ /// The metadata key
+ /// The predicate to check if the metadata key exists
+ /// True if the metadata value matches the predicate
+ ///
public static bool HasMetadata(this IReason reason, string key, Func
public Dictionary Metadata { get; }
+ ///
+ /// Default constructor
+ ///
protected Success()
{
Metadata = new Dictionary();
}
+ ///
+ /// Creates a new instance of and initializes the property
+ ///
+ /// The message
public Success(string message) : this()
{
Message = message;
@@ -50,6 +57,10 @@ public Success WithMetadata(Dictionary metadata)
return this;
}
+ ///
+ /// ToString override
+ ///
+ ///
public override string ToString()
{
return new ReasonStringBuilder()
diff --git a/src/FluentResults/Results/Result.cs b/src/FluentResults/Results/Result.cs
index c466ab4..0b03a0b 100644
--- a/src/FluentResults/Results/Result.cs
+++ b/src/FluentResults/Results/Result.cs
@@ -6,8 +6,14 @@
// ReSharper disable once CheckNamespace
namespace FluentResults
{
+ ///
+ /// Implementation of a Result
+ ///
public partial class Result : ResultBase
{
+ ///
+ /// Default constructor
+ ///
public Result()
{ }
@@ -38,6 +44,11 @@ public Result MapSuccesses(Func successMapper)
.WithSuccesses(Successes.Select(successMapper));
}
+ ///
+ /// Convert result without value to a result containing a value
+ ///
+ /// Type of the value
+ /// Value to add to the new result
public Result ToResult(TNewValue newValue = default)
{
return new Result()
@@ -186,17 +197,29 @@ public async ValueTask Bind(Func> action)
return result;
}
+ ///
+ /// Implict conversion from to a
+ ///
+ /// The error
public static implicit operator Result(Error error)
{
return Fail(error);
}
+ ///
+ /// Implict conversion from to a
+ ///
+ /// The errors
public static implicit operator Result(List errors)
{
return Fail(errors);
}
}
+ ///
+ /// Definition of a result with a value of type
+ ///
+ /// The type of the value
public interface IResult : IResultBase
{
///
@@ -210,8 +233,15 @@ public interface IResult : IResultBase
TValue ValueOrDefault { get; }
}
+ ///
+ /// A result containing a value of type
+ ///
+ /// The type of the value
public class Result : ResultBase>, IResult
{
+ ///
+ /// Default constructor
+ ///
public Result()
{ }
@@ -452,6 +482,9 @@ public async ValueTask Bind(Func> action)
return result;
}
+ ///
+ /// ToString implementation
+ ///
public override string ToString()
{
var baseString = base.ToString();
@@ -459,16 +492,25 @@ public override string ToString()
return $"{baseString}, {valueString}";
}
+ ///
+ /// Implicit conversion from without a value to having the default value
+ ///
public static implicit operator Result(Result result)
{
return result.ToResult(default);
}
+ ///
+ /// Implicit conversion from having a value to without a value
+ ///
public static implicit operator Result