If I have a function bool Foo(string? input)
, then I can annotate it to indicate that if the return is true
then input
is not null:
public static bool Foo([NotNullWhen(true)] string? input)
Is it possible to do that (or something similar) for a property of an argument? I'm thinking something along the lines of
public class AClass { string? NullableString {get;set;}}
public static bool Foo([PropertyNotNullWhen(true, nameof(AClass.NullableString))] AClass input)
I don't think MemberNotNullWhen
will work in this case, because it only applies to methonds, properties, and indexers and not the arguments to them.