fix attribute on HasValue

This commit is contained in:
2025-02-14 14:09:24 -05:00
parent 766eb8a8c2
commit 27e891e80e
2 changed files with 3 additions and 1 deletions

View File

@@ -8,7 +8,7 @@
<PropertyGroup> <PropertyGroup>
<PackageId>MaybeError</PackageId> <PackageId>MaybeError</PackageId>
<Version>1.0.3</Version> <Version>1.0.4</Version>
<Authors>Amatsugu</Authors> <Authors>Amatsugu</Authors>
<PackageDescription>Errors as values</PackageDescription> <PackageDescription>Errors as values</PackageDescription>
<RepositoryUrl>https://github.com/Amatsugu/MaybeError</RepositoryUrl> <RepositoryUrl>https://github.com/Amatsugu/MaybeError</RepositoryUrl>

View File

@@ -9,6 +9,7 @@ public interface IValueMaybe<T, E> where T : struct where E : Error
{ {
[MemberNotNullWhen(true, nameof(Error))] [MemberNotNullWhen(true, nameof(Error))]
bool HasError { get; } bool HasError { get; }
[MemberNotNullWhen(false, nameof(Error))]
bool HasValue => !HasError; bool HasValue => !HasError;
E? Error { get; } E? Error { get; }
T Value { get; } T Value { get; }
@@ -18,6 +19,7 @@ public readonly struct ValueMaybe<T, E> : IValueMaybe<T, E> where T : struct whe
{ {
[MemberNotNullWhen(true, nameof(Error))] [MemberNotNullWhen(true, nameof(Error))]
public readonly bool HasError { get; } public readonly bool HasError { get; }
[MemberNotNullWhen(false, nameof(Error))]
public readonly bool HasValue => !HasError; public readonly bool HasValue => !HasError;
public readonly E? Error { get; } public readonly E? Error { get; }
public readonly T Value => HasError ? throw Error.GetException() : _value; public readonly T Value => HasError ? throw Error.GetException() : _value;