Consider the following code:
C#using System;
namespace CodeRushIssue
{
class Program
{
private static int? Foo;
static void Main( string[] args )
{
var bar = Foo.HasValue ? DoSomething( Foo.Value ) : "baz";
}
private static string DoSomething( int value ) { throw new NotImplementedException(); }
}
}
Code Rush suggests to refactor to
C#using System;
namespace CodeRushIssue
{
class Program
{
private static int? Foo;
static void Main( string[] args )
{
var bar = DoSomething( Foo.Value ) ?? "baz";
}
private static string DoSomething( int value ) { throw new NotImplementedException(); }
}
}
but the new code is not equivalent and throws an exception when Foo is null.
Hello Dominic,
Thank you for pointing out this issue and providing a code sample.
I have reproduced this issue, and we will fix this behavior in future releases.
We will notify you as soon as we have any results.