Skip to content

Commit 32ff702

Browse files
committed
Add implicit conversion from bool to ServiceResult.
1 parent fe0c088 commit 32ff702

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Initium/Results/ServiceResult.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ public ServiceResult WithMetadata(string key, string value)
117117
/// </summary>
118118
/// <param name="result">The <see cref="ServiceResult"/> to convert.</param>
119119
public static implicit operator bool(ServiceResult result) => result.Success;
120+
121+
/// <summary>
122+
/// Converts a boolean value to a <see cref="ServiceResult"/>.
123+
/// </summary>
124+
/// <param name="isSuccess">
125+
/// A boolean indicating the result status: <c>true</c> for success, <c>false</c> for an error.
126+
/// </param>
127+
/// <returns>
128+
/// A <see cref="ServiceResult"/> instance representing the success or error state.
129+
/// </returns>
130+
public static implicit operator ServiceResult(bool isSuccess) => isSuccess ? Ok() : Error();
131+
120132
}
121133

122134
/// <summary>

0 commit comments

Comments
 (0)