Skip to content
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

CA1507: Use nameof in place of string #10294

Open
Tracked by #10270
himgoyalmicro opened this issue Jan 16, 2025 · 0 comments · May be fixed by #10186
Open
Tracked by #10270

CA1507: Use nameof in place of string #10294

himgoyalmicro opened this issue Jan 16, 2025 · 0 comments · May be fixed by #10186
Assignees
Labels
area-Styling Indicates if an issue or a PR is for style changes 🚧 work in progress

Comments

@himgoyalmicro
Copy link
Contributor

himgoyalmicro commented Jan 16, 2025

Link to the issue description: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1507

Rule Description

Rule CA1507 flags the use of a string literal as an argument to a method or constructor where a nameof (NameOf in Visual Basic) expression would add maintainability. The rule fires if all of the following conditions are met:

  • The argument is a string literal or constant.
  • The argument corresponds to a string-typed parameter of the method or the constructor that's being invoked (that is, there is no conversion involved at the call site).
  • Either:
    • The declared name of the parameter is paramName and the constant value of the string literal matches the name of a parameter of the method, lambda, or local function within which the method or constructor is being invoked.
    • The declared name of the parameter is propertyName and the constant value of the string literal matches the name of a property of the type within which the method or constructor is being invoked.
@himgoyalmicro himgoyalmicro added the area-Styling Indicates if an issue or a PR is for style changes label Jan 16, 2025
@himgoyalmicro himgoyalmicro self-assigned this Jan 16, 2025
@himgoyalmicro himgoyalmicro changed the title CA1507 CA1507: Use nameof in place of string Jan 16, 2025
@himgoyalmicro himgoyalmicro linked a pull request Jan 16, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Styling Indicates if an issue or a PR is for style changes 🚧 work in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant