Skip to content

Commit 1653fb7

Browse files
Add MaybeNull attribute on ValueOrNull
1 parent fd087ae commit 1653fb7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Hamlet/NullableAttributes.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace System.Diagnostics.CodeAnalysis
2+
{
3+
/// <summary>Specifies that an output may be null even if the corresponding type disallows it.</summary>
4+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
5+
internal sealed class MaybeNullAttribute : Attribute
6+
{ }
7+
}

src/Hamlet/Option.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34

45
namespace Hamlet
56
{
@@ -148,6 +149,7 @@ public static U Match<T, U>(this Option<T> option, Func<T, U> some, Func<U> none
148149
/// <typeparam name="T">The type of the option's value.</typeparam>
149150
/// <param name="option">The option to get the value from.</param>
150151
/// <returns>The option's value if it's <c>Some</c>, or <c>null</c> if it's <c>None</c>.</returns>
152+
[return: MaybeNull]
151153
public static T ValueOrNull<T>(this Option<T> option)
152154
where T : class?
153155
{

0 commit comments

Comments
 (0)