+4
-4
@@ -64,7 +64,7 @@ public readonly partial struct Result : IEquatable<Result>
|
||||
public static implicit operator Result(Error error) => new(error ?? throw new ArgumentNullException(nameof(error)));
|
||||
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator Result(Exception exception) => new(
|
||||
new ExceptionalError(exception ?? throw new ArgumentNullException(nameof(exception))));
|
||||
Error.New(exception ?? throw new ArgumentNullException(nameof(exception))));
|
||||
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator Result<SuccessUnit>(Result result) => result.State switch
|
||||
{
|
||||
@@ -75,8 +75,8 @@ public readonly partial struct Result : IEquatable<Result>
|
||||
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator Result(SuccessUnit _) => new(null);
|
||||
|
||||
[Pure] public bool IsSuccess => Error is null;
|
||||
[Pure] public bool IsFailure => Error is not null;
|
||||
[Pure] public bool IsSuccess => State == ResultState.Success;
|
||||
[Pure] public bool IsFailure => State == ResultState.Error;
|
||||
|
||||
[Pure] public bool TryGetValue([MaybeNullWhen(false)]out SuccessUnit? u, [MaybeNullWhen(true), NotNullWhen(false)]out Error? error)
|
||||
{
|
||||
@@ -236,7 +236,7 @@ public readonly struct Result<T> : IEquatable<Result<T>>
|
||||
if (typeof(R).IsAssignableFrom(typeof(T)) && Value is null)
|
||||
return default(R)!;
|
||||
|
||||
return (R)(object)Value!;
|
||||
return (R)(object)Value!; // throws InvalidCastException by design. should not use cast on incompatible types
|
||||
}
|
||||
|
||||
default: throw new ResultNotInitializedException();
|
||||
|
||||
Reference in New Issue
Block a user