I have the following class
C#public class Foo
{
private readonly string _bar;
public Foo( string bar )
{
_bar = bar;
}
}
CTRL + ., Add Contract, Throws Exception creates the following code
C#public class Foo
{
private readonly string _bar;
public Foo( string bar )
{
_bar = bar ?? throw new ArgumentException( $"{nameof( bar )} is null or empty.", nameof( bar ) );
}
}
The old (and correct) behavior was:
C#public class Foo
{
private readonly string _bar;
public Foo( string bar )
{
if ( string.IsNullOrWhiteSpace( bar ) )
throw new ArgumentException( $"{nameof( bar )} is null or empty.", nameof( bar ) );
_bar = bar;
}
}
The null-coalescing expression will not throw if the parameter is an empty string.
Hello Dominic,
Thank you for pointing out this issue to us. We will fix it soon. You will be notified once we do this.