This code in C# 9.0/.NET 5.0:
public record Data(string Code)
{
public string Code { get; } = Code ?? throw new ArgumentNullException(nameof(Code));
}
Result in csharpsquid:S3928/“Parameter names used into ArgumentException constructors should match an existing one”.
The message is “Code Smell: The parameter name ‘Code’ is not declared in the argument list.” but ‘Code’ is the constructor argument used to initialise the Code
property.".
I believe this to be a false positive because Code is defined in the record constructor parameters.
This code:
using System;
public class Program
{
public static void Main() => new Data(null!);
}
public record Data(string Code)
{
public string Code { get; } = Code ?? throw new ArgumentNullException(nameof(Code));
}
Results in “System.ArgumentNullException: Value cannot be null. (Parameter ‘Code’)” as expected.