-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
S2743: Add support for record struct #5607
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a nice rule. Just some minor suggestions.
|| typeDeclaration.TypeParameterList == null | ||
|| typeDeclaration.TypeParameterList.Parameters.Count < 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|| typeDeclaration.TypeParameterList == null | |
|| typeDeclaration.TypeParameterList.Parameters.Count < 1) | |
|| c.Node is not TypeDeclarationSyntax { TypeParameterList: { Parameters: { Count: > 0 } } } typeDeclaration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csaba-sagi-sonarsource That's one of the places where C#10 would remove some clutter:
// C# 9
c.Node is not TypeDeclarationSyntax { TypeParameterList: { Parameters: { Count: > 0 } } } typeDeclaration)
// C# 10
c.Node is not TypeDeclarationSyntax { TypeParameterList.Parameters.Count: > 0 } typeDeclaration)
var fields = typeDeclaration.Members.OfType<FieldDeclarationSyntax>().Where(x => x.Modifiers.Any(SyntaxKind.StaticKeyword)); | ||
foreach (var field in fields.Where(x => !HasGenericType(c, x.Declaration.Type, typeParameterNames))) | ||
{ | ||
field.Declaration.Variables.ToList().ForEach(variable => CheckMember(variable, variable.Identifier.GetLocation(), typeParameterNames, c)); | ||
field.Declaration.Variables.ToList().ForEach(variable => CheckMember(c, variable, variable.Identifier.GetLocation(), typeParameterNames)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified:
var variables = typeDeclaration.Members
.OfType<FieldDeclarationSyntax>()
.Where(x => x.Modifiers.Any(SyntaxKind.StaticKeyword) && !HasGenericType(c, x.Declaration.Type, typeParameterNames))
.SelectMany(x => x.Declaration.Variables);
foreach (var variable in variables)
{
CheckMember(c, variable, variable.Identifier.GetLocation(), typeParameterNames);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
No description provided.