With Code Cleanup options set such that the "Use 'naemof'" option is checked, given a method like this:
C#public void Test()
{
var key = new ApiKey
{
Id = 5
};
if(String.Compare(key.Id.ToString(), "key") == 0)
{
throw new Exception();
}
}
When I apply Code Cleanup, the "nameof" operator gets incorrectly added to literally every string constant that matches a variable name, which results in things like this:
C#public void Test()
{
var key = new ApiKey
{
Id = 5
};
if (string.Compare(key.Id.ToString(), nameof(key)) == 0)
{
throw new Exception();
}
}
I would expect "nameof" to really only be applied in expressions that throw an exception or otherwise would normally be expected to be using the names of variables.
Hi Travis,
Thank you for pointing out this issue. I passed this ticket to our developers. Once they find an appropriate solution, you will be immediately notified via email.