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

Add an analyzer which recommends nameof usage #2991

Closed
bradwilson opened this issue Aug 1, 2024 · 4 comments · Fixed by #3062
Closed

Add an analyzer which recommends nameof usage #2991

bradwilson opened this issue Aug 1, 2024 · 4 comments · Fixed by #3062

Comments

@bradwilson
Copy link
Member

Whenever we use string properties on attributes intended to point at a member, we should encourage the use of nameof rather than hard-coded strings.

This includes, at least (please look and see if there are others):

  • IFactAttribute.SkipUnless
  • IFactAttribute.SkipWhen
  • MemberDataAttribute constructor
@hpatel292-seneca
Copy link
Contributor

@bradwilson Can I work on it?

@bradwilson
Copy link
Member Author

@hpatel292-seneca Sure!

@hpatel292-seneca
Copy link
Contributor

Hi @bradwilson

I wanted to confirm if I should proceed with updating the XML documentation for the MemberDataAttribute class to encourage the use of the nameof operator for the memberName parameter. Specifically, I would add a recommendation in the <param> tag, such as:

"It is recommended to use the nameof operator to ensure compile-time safety, e.g., nameof(SomeMemberName)."

Please let me know if this approach aligns with the project's guidelines or if additional changes are needed.

@bradwilson
Copy link
Member Author

@hpatel292-seneca Yep, that'd be a great addition to all the common places people should be using nameof.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants