Background and motivation
It's common for TryParse methods to set the out parameter to null when returning false. The current IParsable / ISpanParsable doesn't allow null values. I think the interface should add [MaybeNullWhen(false)] to the out parameter.
API Proposal
namespaceSystem;publicinterfaceISpanParsable<T>{// existingstaticabstractboolTryParse(ReadOnlySpan<char>s,IFormatProvider?provider,outTSelfresult);// suggestedstaticabstractboolTryParse(ReadOnlySpan<char>s,IFormatProvider?provider,[MaybeNullWhen(false)]outTSelfresult);}publicinterfaceIParsable<T>{// existingstaticabstractboolTryParse([NotNullWhen(true)]string?s,IFormatProvider?provider,outTSelfresult);// suggestedstaticabstractboolTryParse([NotNullWhen(true)]string?s,IFormatProvider?provider,[MaybeNullWhen(false)]outTSelfresult);}API Usage
publicclassSample:ISpanParsable<Sample>{publicstaticSampleParse(strings,IFormatProvider?provider)=>newSample();publicstaticSampleParse(ReadOnlySpan<char>s,IFormatProvider?provider)=>newSample();publicstaticboolTryParse([NotNullWhen(true)]string?s,IFormatProvider?provider,outSampleresult){result=default;// should be validreturnfalse;}publicstaticboolTryParse(ReadOnlySpan<char>s,IFormatProvider?provider,outSampleresult){result=default;// should be validreturnfalse;}}Alternative Designs
No response
Risks
No response
Background and motivation
It's common for
TryParsemethods to set the out parameter tonullwhen returningfalse. The currentIParsable/ISpanParsabledoesn't allow null values. I think the interface should add[MaybeNullWhen(false)]to the out parameter.API Proposal
API Usage
Alternative Designs
No response
Risks
No response