I'm trying to fully decorate an API that uses (what I call) the throwOnError pattern.
I know some people dislike it but this is not the point: it is used by people far more clever than me, for instance in the Assembly.GetType method:
public virtual Type? GetType(string name, bool throwOnError)
I'm a little bit disappointed: it seems that currently (C#9/net5), it is not possible to state that the return cannot be null as long as throwOnError is true. Something like: [return: NotNullIfTrue( "throwOnError" )].
The source here is (sadly) naked: https://source.dot.net/#System.Private.CoreLib/Assembly.cs,106
Does anyone has a solution to this? Should we wait for a NotNullIfTrue attribute?
PS: I don't want to use [DoesNotReturnIf(true)] since this is obvisoulsy a too strong assertion.