Skip to content

Commit

Permalink
Add MaybeNullWhen( attribute to IParsable.TryParse / ISpanParsable.Tr…
Browse files Browse the repository at this point in the history
…yParse (dotnet#71381)
  • Loading branch information
meziantou authored Jun 30, 2022
1 parent bfb571f commit 7cf661d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public interface IParsable<TSelf>
/// <param name="provider">An object that provides culture-specific formatting information about <paramref name="s" />.</param>
/// <param name="result">On return, contains the result of succesfully parsing <paramref name="s" /> or an undefined value on failure.</param>
/// <returns><c>true</c> if <paramref name="s" /> was successfully parsed; otherwise, <c>false</c>.</returns>
static abstract bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out TSelf result);
static abstract bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(returnValue: false)] out TSelf result);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;

namespace System
{
/// <summary>Defines a mechanism for parsing a span of characters to a value.</summary>
Expand All @@ -21,6 +23,6 @@ public interface ISpanParsable<TSelf> : IParsable<TSelf>
/// <param name="provider">An object that provides culture-specific formatting information about <paramref name="s" />.</param>
/// <param name="result">On return, contains the result of succesfully parsing <paramref name="s" /> or an undefined value on failure.</param>
/// <returns><c>true</c> if <paramref name="s" /> was successfully parsed; otherwise, <c>false</c>.</returns>
static abstract bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out TSelf result);
static abstract bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, [MaybeNullWhen(returnValue: false)] out TSelf result);
}
}
4 changes: 2 additions & 2 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3805,7 +3805,7 @@ public partial interface IObserver<in T>
public partial interface IParsable<TSelf> where TSelf : System.IParsable<TSelf>
{
static abstract TSelf Parse(string s, System.IFormatProvider? provider);
static abstract bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out TSelf result);
static abstract bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TSelf result);
}
public partial interface IProgress<in T>
{
Expand All @@ -3818,7 +3818,7 @@ public partial interface ISpanFormattable : System.IFormattable
public partial interface ISpanParsable<TSelf> : System.IParsable<TSelf> where TSelf : System.ISpanParsable<TSelf>
{
static abstract TSelf Parse(System.ReadOnlySpan<char> s, System.IFormatProvider? provider);
static abstract bool TryParse(System.ReadOnlySpan<char> s, System.IFormatProvider? provider, out TSelf result);
static abstract bool TryParse(System.ReadOnlySpan<char> s, System.IFormatProvider? provider, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TSelf result);
}
public partial class Lazy<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>
{
Expand Down

0 comments on commit 7cf661d

Please sign in to comment.