I get a compiler warning that started when upgrading to FluentAssertions 4.2.2. In the following code, if I call EndsWith(nameof(x)), I get an ambiguous call warning. If instead I define var foo = nameof(x)and invoke EndsWith(foo), it compiles cleanly. The code works fine in both scenarios.
My questions are, why is this happening, and is there a workaround other than storing the result nameof()in a variable?
[Test]
public void TestLastNamesAreSame()
{
var original = new MyDTO("fred", "jones");
var expected = new MyDTO("barney", "jones");
expected.ShouldBeEquivalentTo(original, o => o
.Excluding(x => x.SelectedMemberPath.EndsWith(nameof(MyDTO.FirstName))));
const string nameOfFirstNameField = nameof(MyDTO.FirstName);
expected.ShouldBeEquivalentTo(original, o => o
.Excluding(x => x.SelectedMemberPath.EndsWith(nameOfFirstNameField)));
}
public class MyDTO
{
public string FirstName { get; }
public string LastName { get; }
public MyDTO(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
}
}
herky source
share