You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A question about the new nullable enable and [MaybeNullWhen(false)] #654
Thanks for catching this - it was a miss on my part. I saw it followed the Dictionary-style TryGet contract and didn't think hard enough about it. What do you suggest? This version has only been out for a few hours.
Hey @StefH, the PR was mine, so I guess I put my two cents here: for the most part [MaybeNullWhen(false)] and [NotNullWhen(true)] is the same, and I don't mind, if it get's changed now or in the future.
That being said Dictionary<TKey, TValue> couldn't use [NotNullWhen(true)] as null might be a valid value for TValue. If it's not valid for TValue, you effectively get [NotNullWhen(true)]. Now looking just add IHelperResolver.TryResolveHelper you can choose either attribute, as TValue would be IHelperDescriptor<HelperOptions> - if you backed it by an Dictionary<TKey, TValue>, but I liked [MaybeNullWhen(false)] better, as it just forwards the underlying guarantee.
I also feel like [MaybeNullWhen(false)] out IHelperDescriptor<HelperOptions> better communicates the expected result. We expect that most of the times, when we actually call this, the user was right and there is a helper. But we want to gracefully handle the case, were there is no helper.
Again: it's up to you, but I would consider it just a boring change, not a fix unless I overlooked something.
Activity
rexm commentedon Aug 5, 2026
Thanks for catching this - it was a miss on my part. I saw it followed the Dictionary-style TryGet contract and didn't think hard enough about it. What do you suggest? This version has only been out for a few hours.
StefH commentedon Aug 5, 2026
I suggest to fix it. And double check all other code which involves TryGet pattern.
And it's not a critical change, so I guess it's not needed to unlist the nuget packages.
TheConstructor commentedon Aug 5, 2026
Hey @StefH, the PR was mine, so I guess I put my two cents here: for the most part
[MaybeNullWhen(false)]and[NotNullWhen(true)]is the same, and I don't mind, if it get's changed now or in the future.That being said
Dictionary<TKey, TValue>couldn't use[NotNullWhen(true)]asnullmight be a valid value forTValue. If it's not valid forTValue, you effectively get[NotNullWhen(true)]. Now looking just addIHelperResolver.TryResolveHelperyou can choose either attribute, asTValuewould beIHelperDescriptor<HelperOptions>- if you backed it by anDictionary<TKey, TValue>, but I liked[MaybeNullWhen(false)]better, as it just forwards the underlying guarantee.I also feel like
[MaybeNullWhen(false)] out IHelperDescriptor<HelperOptions>better communicates the expected result. We expect that most of the times, when we actually call this, the user was right and there is a helper. But we want to gracefully handle the case, were there is no helper.Again: it's up to you, but I would consider it just a boring change, not a fix unless I overlooked something.
Merge pull request #655 from Handlebars-Net/fix/issue-654-nullable-tr…
fix: use NotNullWhen(true) instead of MaybeNullWhen(false) for concre…