Skip to content

Commit e04d1a1

Browse files
Added xmldoc for Result<T> members.
1 parent 6925521 commit e04d1a1

File tree

4 files changed

+351
-6
lines changed

4 files changed

+351
-6
lines changed

OnixLabs.Core/Optional.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ internal Optional()
7878
public static implicit operator Optional<T>(T value) => Some(value);
7979

8080
/// <summary>
81-
/// Gets the underlying value of the current <see cref="Optional{T}"/> instance;
81+
/// Gets the underlying value of the specified <see cref="Optional{T}"/> instance;
8282
/// otherwise throws an <see cref="InvalidOperationException"/> if the value is absent.
8383
/// </summary>
8484
/// <param name="value">The <see cref="Optional{T}"/> instance from which to obtain the underlying value.</param>
8585
/// <returns>
86-
/// Returns the underlying value of the current <see cref="Optional{T}"/> instance;
86+
/// Returns the underlying value of the specified <see cref="Optional{T}"/> instance;
8787
/// otherwise throws an <see cref="InvalidOperationException"/> if the value is absent.
8888
/// </returns>
8989
/// <exception cref="InvalidOperationException">If the underlying value is absent.</exception>

OnixLabs.Core/Result.Failure.cs

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,134 @@
1616

1717
namespace OnixLabs.Core;
1818

19+
/// <summary>
20+
/// Represents a failed result.
21+
/// </summary>
22+
/// <typeparam name="T">The type of the underlying result value.</typeparam>
1923
public sealed class Failure<T> : Result<T>, IValueEquatable<Failure<T>>
2024
{
21-
public Failure(Exception exception) => Exception = exception;
22-
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="Failure{T}"/> class.
27+
/// </summary>
28+
/// <param name="exception">The underlying exception representing the failed result.</param>
29+
internal Failure(Exception exception) => Exception = exception;
30+
31+
/// <summary>
32+
/// Gets the underlying result exception.
33+
/// </summary>
2334
public Exception Exception { get; }
2435

36+
/// <summary>
37+
/// Performs an equality comparison between two object instances.
38+
/// </summary>
39+
/// <param name="left">The left-hand instance to compare.</param>
40+
/// <param name="right">The right-hand instance to compare.</param>
41+
/// <returns>Returns <see langword="true"/> if the left-hand instance is equal to the right-hand instance; otherwise, <see langword="false"/>.</returns>
2542
public static bool operator ==(Failure<T> left, Failure<T> right) => Equals(left, right);
2643

44+
/// <summary>
45+
/// Performs an inequality comparison between two object instances.
46+
/// </summary>
47+
/// <param name="left">The left-hand instance to compare.</param>
48+
/// <param name="right">The right-hand instance to compare.</param>
49+
/// <returns>Returns <see langword="true"/> if the left-hand instance is not equal to the right-hand instance; otherwise, <see langword="false"/>.</returns>
2750
public static bool operator !=(Failure<T> left, Failure<T> right) => !Equals(left, right);
2851

52+
/// <summary>
53+
/// Checks whether the current object is equal to another object of the same type.
54+
/// </summary>
55+
/// <param name="other">An object to compare with the current object.</param>
56+
/// <returns>Returns <see langword="true"/> if the current object is equal to the other parameter; otherwise, <see langword="false"/>.</returns>
2957
public bool Equals(Failure<T>? other) => ReferenceEquals(this, other) || other is not null && Equals(other.Exception, Exception);
3058

59+
/// <summary>
60+
/// Checks for equality between the current instance and another object.
61+
/// </summary>
62+
/// <param name="obj">The object to check for equality.</param>
63+
/// <returns>Returns <see langword="true"/> if the object is equal to the current instance; otherwise, <see langword="false"/>.</returns>
3164
public override bool Equals(object? obj) => Equals(obj as Failure<T>);
3265

66+
/// <summary>
67+
/// Serves as a hash code function for the current instance.
68+
/// </summary>
69+
/// <returns>Returns a hash code for the current instance.</returns>
3370
public override int GetHashCode() => Exception.GetHashCode();
3471

72+
/// <summary>
73+
/// Gets the underlying value of the current <see cref="Result{T}"/> instance, if the underlying value is present;
74+
/// otherwise returns the default <typeparam name="T"/> value.
75+
/// </summary>
76+
/// <returns>
77+
/// Returns the underlying value of the current <see cref="Result{T}"/> instance, if the underlying value is present;
78+
/// otherwise returns the default <typeparam name="T"/> value.
79+
/// </returns>
3580
public override T? GetValueOrDefault() => default;
3681

82+
/// <summary>
83+
/// Gets the underlying value of the current <see cref="Result{T}"/> instance, if the underlying value is present;
84+
/// otherwise returns the specified default value.
85+
/// </summary>
86+
/// <param name="defaultValue">The default value to return in the event that the underlying value is absent.</param>
87+
/// <returns>
88+
/// Returns the underlying value of the current <see cref="Result{T}"/> instance, if the underlying value is present;
89+
/// otherwise returns the specified default value.
90+
/// </returns>
3791
public override T GetValueOrDefault(T defaultValue) => defaultValue;
3892

93+
/// <summary>
94+
/// Gets the underlying value of the current <see cref="Result{T}"/> instance;
95+
/// otherwise throws the underlying exception if the current <see cref="Result{T}"/> is in a failed stated.
96+
/// </summary>
97+
/// <returns>
98+
/// Returns the underlying value of the current <see cref="Result{T}"/> instance;
99+
/// otherwise throws the underlying exception if the current <see cref="Result{T}"/> is in a failed stated.
100+
/// </returns>
39101
public override T GetValueOrThrow() => throw Exception;
40102

103+
/// <summary>
104+
/// Executes the action that matches the value of the current <see cref="Result{T}"/> instance.
105+
/// </summary>
106+
/// <param name="success">The action to execute when the current <see cref="Result{T}"/> instance is in a successful state.</param>
107+
/// <param name="failure">The action to execute when the current <see cref="Result{T}"/> instance is in a failed state.</param>
41108
public override void Match(Action<T> success, Action<Exception> failure) => failure(Exception);
42109

110+
/// <summary>
111+
/// Executes the function that matches the value of the current <see cref="Result{T}"/> instance and returns its result.
112+
/// </summary>
113+
/// <param name="success">The action to execute when the current <see cref="Result{T}"/> instance is in a successful state.</param>
114+
/// <param name="failure">The action to execute when the current <see cref="Result{T}"/> instance is in a failed state.</param>
115+
/// <typeparam name="TResult">The underlying type of the result produced by the matching function.</typeparam>
116+
/// <returns>
117+
/// Returns the result of the <paramref name="success"/> function if the current <see cref="Result{T}"/> instance is in a successful state;
118+
/// otherwise, returns the result of the <paramref name="failure"/> function if the current <see cref="Result{T}"/> instance is in a failed state.
119+
/// </returns>
43120
public override TResult Match<TResult>(Func<T, TResult> success, Func<Exception, TResult> failure) => failure(Exception);
44121

122+
/// <summary>
123+
/// Applies the provided selector function to the value of the current <see cref="Result{T}"/> instance.
124+
/// </summary>
125+
/// <param name="selector">The function to apply to the value of the current <see cref="Result{T}"/> instance.</param>
126+
/// <typeparam name="TResult">The underlying type of the result produced by the selector function.</typeparam>
127+
/// <returns>
128+
/// Returns a new <see cref="Result{TResult}"/> instance containing the result of the function if the current
129+
/// <see cref="Result{T}"/> instance is in a successful state; otherwise, returns the current failed <see cref="Result{T}"/> instance.
130+
/// </returns>
45131
public override Result<TResult> Select<TResult>(Func<T, TResult> selector) => Result<TResult>.Failure(Exception);
46132

133+
/// <summary>
134+
/// Applies the provided selector function to the value of the current <see cref="Result{T}"/> instance.
135+
/// </summary>
136+
/// <param name="selector">The function to apply to the value of the current <see cref="Result{T}"/> instance.</param>
137+
/// <typeparam name="TResult">The underlying type of the result produced by the selector function.</typeparam>
138+
/// <returns>
139+
/// Returns a new <see cref="Result{TResult}"/> instance containing the result of the function if the current
140+
/// <see cref="Result{T}"/> instance is in a successful state; otherwise, returns the current failed <see cref="Result{T}"/> instance.
141+
/// </returns>
47142
public override Result<TResult> SelectMany<TResult>(Func<T, Result<TResult>> selector) => Result<TResult>.Failure(Exception);
48143

144+
/// <summary>
145+
/// Returns a <see cref="String"/> that represents the current object.
146+
/// </summary>
147+
/// <returns>Returns a <see cref="String"/> that represents the current object.</returns>
49148
public override string ToString() => Exception.ToString();
50149
}

OnixLabs.Core/Result.Success.cs

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,134 @@
1616

1717
namespace OnixLabs.Core;
1818

19+
/// <summary>
20+
/// Represents a successful result.
21+
/// </summary>
22+
/// <typeparam name="T">The type of the underlying result value.</typeparam>
1923
public sealed class Success<T> : Result<T>, IValueEquatable<Success<T>>
2024
{
21-
public Success(T value) => Value = value;
22-
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="Success{T}"/> class.
27+
/// </summary>
28+
/// <param name="value">The underlying value representing the successful result.</param>
29+
internal Success(T value) => Value = value;
30+
31+
/// <summary>
32+
/// Gets the underlying result value.
33+
/// </summary>
2334
public T Value { get; }
2435

36+
/// <summary>
37+
/// Performs an equality comparison between two object instances.
38+
/// </summary>
39+
/// <param name="left">The left-hand instance to compare.</param>
40+
/// <param name="right">The right-hand instance to compare.</param>
41+
/// <returns>Returns <see langword="true"/> if the left-hand instance is equal to the right-hand instance; otherwise, <see langword="false"/>.</returns>
2542
public static bool operator ==(Success<T> left, Success<T> right) => Equals(left, right);
2643

44+
/// <summary>
45+
/// Performs an inequality comparison between two object instances.
46+
/// </summary>
47+
/// <param name="left">The left-hand instance to compare.</param>
48+
/// <param name="right">The right-hand instance to compare.</param>
49+
/// <returns>Returns <see langword="true"/> if the left-hand instance is not equal to the right-hand instance; otherwise, <see langword="false"/>.</returns>
2750
public static bool operator !=(Success<T> left, Success<T> right) => Equals(left, right);
2851

52+
/// <summary>
53+
/// Checks whether the current object is equal to another object of the same type.
54+
/// </summary>
55+
/// <param name="other">An object to compare with the current object.</param>
56+
/// <returns>Returns <see langword="true"/> if the current object is equal to the other parameter; otherwise, <see langword="false"/>.</returns>
2957
public bool Equals(Success<T>? other) => ReferenceEquals(this, other) || other is not null && Equals(other.Value, Value);
3058

59+
/// <summary>
60+
/// Checks for equality between the current instance and another object.
61+
/// </summary>
62+
/// <param name="obj">The object to check for equality.</param>
63+
/// <returns>Returns <see langword="true"/> if the object is equal to the current instance; otherwise, <see langword="false"/>.</returns>
3164
public override bool Equals(object? obj) => Equals(obj as Success<T>);
3265

66+
/// <summary>
67+
/// Serves as a hash code function for the current instance.
68+
/// </summary>
69+
/// <returns>Returns a hash code for the current instance.</returns>
3370
public override int GetHashCode() => Value?.GetHashCode() ?? default;
3471

72+
/// <summary>
73+
/// Gets the underlying value of the current <see cref="Result{T}"/> instance, if the underlying value is present;
74+
/// otherwise returns the default <typeparam name="T"/> value.
75+
/// </summary>
76+
/// <returns>
77+
/// Returns the underlying value of the current <see cref="Result{T}"/> instance, if the underlying value is present;
78+
/// otherwise returns the default <typeparam name="T"/> value.
79+
/// </returns>
3580
public override T? GetValueOrDefault() => Value;
3681

82+
/// <summary>
83+
/// Gets the underlying value of the current <see cref="Result{T}"/> instance, if the underlying value is present;
84+
/// otherwise returns the specified default value.
85+
/// </summary>
86+
/// <param name="defaultValue">The default value to return in the event that the underlying value is absent.</param>
87+
/// <returns>
88+
/// Returns the underlying value of the current <see cref="Result{T}"/> instance, if the underlying value is present;
89+
/// otherwise returns the specified default value.
90+
/// </returns>
3791
public override T GetValueOrDefault(T defaultValue) => Value ?? defaultValue;
3892

93+
/// <summary>
94+
/// Gets the underlying value of the current <see cref="Result{T}"/> instance;
95+
/// otherwise throws the underlying exception if the current <see cref="Result{T}"/> is in a failed stated.
96+
/// </summary>
97+
/// <returns>
98+
/// Returns the underlying value of the current <see cref="Result{T}"/> instance;
99+
/// otherwise throws the underlying exception if the current <see cref="Result{T}"/> is in a failed stated.
100+
/// </returns>
39101
public override T GetValueOrThrow() => Value;
40102

103+
/// <summary>
104+
/// Executes the action that matches the value of the current <see cref="Result{T}"/> instance.
105+
/// </summary>
106+
/// <param name="success">The action to execute when the current <see cref="Result{T}"/> instance is in a successful state.</param>
107+
/// <param name="failure">The action to execute when the current <see cref="Result{T}"/> instance is in a failed state.</param>
41108
public override void Match(Action<T> success, Action<Exception> failure) => success(Value);
42109

110+
/// <summary>
111+
/// Executes the function that matches the value of the current <see cref="Result{T}"/> instance and returns its result.
112+
/// </summary>
113+
/// <param name="success">The action to execute when the current <see cref="Result{T}"/> instance is in a successful state.</param>
114+
/// <param name="failure">The action to execute when the current <see cref="Result{T}"/> instance is in a failed state.</param>
115+
/// <typeparam name="TResult">The underlying type of the result produced by the matching function.</typeparam>
116+
/// <returns>
117+
/// Returns the result of the <paramref name="success"/> function if the current <see cref="Result{T}"/> instance is in a successful state;
118+
/// otherwise, returns the result of the <paramref name="failure"/> function if the current <see cref="Result{T}"/> instance is in a failed state.
119+
/// </returns>
43120
public override TResult Match<TResult>(Func<T, TResult> success, Func<Exception, TResult> failure) => success(Value);
44121

122+
/// <summary>
123+
/// Applies the provided selector function to the value of the current <see cref="Result{T}"/> instance.
124+
/// </summary>
125+
/// <param name="selector">The function to apply to the value of the current <see cref="Result{T}"/> instance.</param>
126+
/// <typeparam name="TResult">The underlying type of the result produced by the selector function.</typeparam>
127+
/// <returns>
128+
/// Returns a new <see cref="Result{TResult}"/> instance containing the result of the function if the current
129+
/// <see cref="Result{T}"/> instance is in a successful state; otherwise, returns the current failed <see cref="Result{T}"/> instance.
130+
/// </returns>
45131
public override Result<TResult> Select<TResult>(Func<T, TResult> selector) => selector(Value);
46132

133+
/// <summary>
134+
/// Applies the provided selector function to the value of the current <see cref="Result{T}"/> instance.
135+
/// </summary>
136+
/// <param name="selector">The function to apply to the value of the current <see cref="Result{T}"/> instance.</param>
137+
/// <typeparam name="TResult">The underlying type of the result produced by the selector function.</typeparam>
138+
/// <returns>
139+
/// Returns a new <see cref="Result{TResult}"/> instance containing the result of the function if the current
140+
/// <see cref="Result{T}"/> instance is in a successful state; otherwise, returns the current failed <see cref="Result{T}"/> instance.
141+
/// </returns>
47142
public override Result<TResult> SelectMany<TResult>(Func<T, Result<TResult>> selector) => selector(Value);
48143

144+
/// <summary>
145+
/// Returns a <see cref="String"/> that represents the current object.
146+
/// </summary>
147+
/// <returns>Returns a <see cref="String"/> that represents the current object.</returns>
49148
public override string ToString() => Value?.ToString() ?? string.Empty;
50149
}

0 commit comments

Comments
 (0)