Requires.NotNull should accept values of type `T?`
9at8 opened this issue · 1 comments
9at8 commented
https://dotnetfiddle.net/rB8FPD
In the following code, the Requires.NotNull call displays a warning
The Requires.NotNull
function should accept values of type T?
instead of T
#nullable enable
using System;
using Microsoft;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
Foo? str = null;
Requires.NotNull(str, "");
}
private class Foo {
}
}
AArnott commented
Thanks for the feedback, but this decision was carefully considered in #37 and the design we have is intentional.
Requires
is for argument validation, and if you call Requires.NotNull
on an argument, the parameter should not be declared as nullable. That is why Requires.NotNull
does not take nullable arguments -- it helps ensure your parameter declaration is honest about your nullable expectations.
In your sample code, Requires
isn't the right class to use. You should use Assumes
for validating your internal state.