Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StyleCopAnalyzers/SA1313 in a positional record: should be disabled?

With C# 9, you can do the following:

public record Person(string FirstName, string LastName);

to define the record Person. This is equivalent to:

public record Person 
{ 
    public string FirstName { get; init; } 
    public string LastName { get; init; }
    public Person(string firstName, string lastName) 
      => (FirstName, LastName) = (firstName, lastName);
    public void Deconstruct(out string firstName, out string lastName) 
      => (firstName, lastName) = (FirstName, LastName);
}

according to this page.

So, the elements FirstName and LastName act both as a property and an argument for the constructor. As properties, these elements should be capitalized, but if I do it, SA1313 complains: Parameter '__' must begin with lower-case letter..

Is it a problem with StyleCop or am I doing something wrong?

like image 456
xavier Avatar asked Nov 17 '20 23:11

xavier


Video Answer


1 Answers

This is a problem in StyleCop and it's been fixed for the 1.2.0-beta.261 release.

like image 122
Reilly Wood Avatar answered Oct 19 '22 04:10

Reilly Wood