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

Proposal: nameof in C# comments #12382

Closed
copernicus365 opened this issue Jul 7, 2016 · 4 comments
Closed

Proposal: nameof in C# comments #12382

copernicus365 opened this issue Jul 7, 2016 · 4 comments

Comments

@copernicus365
Copy link

It would be nice if the nameof keyword could be used in XML comments. Renaming the type in code would then update the type names in the comments (like paramrefs already do).

Perhaps this could be made available by prepending the @ symbol before nameof:

/// <summary>
/// Lorem ipsum @nameof(Foo) likes @nameof(Bar).
/// </summary>
public class Foo { }
public class Bar { }

XML comment consumers (like VisualStudio) could leave these just as they are, though it's possible some consumers could, when pretty displaying the comments (for display purposes only, like in a popup), treat @nameof(Bar) like it is <c>Bar</c>.

If this were feasible, maybe it would be worth considering even allowing constants in comments as well. That would be one terrific way of getting around the annoying problem of when it would be nice to share a comment or part of a comment in multiple overloads, etc. Maybe for simplicity's sake (simple because the keyword makes things straightforward) this could be done by using the @nameof(Foo.Pi) keyword there too. But let's keep this constants business separate for now.

FYI, Recommended Tags for Documentation Comments (C# Programming Guide)

@svick
Copy link
Contributor

svick commented Jul 7, 2016

How is @nameof(Foo) different from <see cref="Foo" />?

@copernicus365
Copy link
Author

copernicus365 commented Jul 7, 2016

Shucks, I forgot about this attribute. It doesn't help that 'see' (which comes up in intellisense) is not so clear what it refers to. But the fact that there is a native XML way of doing this will move the bar high before a non-XML way were used like this. So I should probably close this, thanks for the info sir. The benefit now would simply be that this is a non-XML way which looks a lot cleaner, and requires only a single keyword, not an XML <elemName attribute="" />. Personally I don't like these wordy XML ways of referencing code types, most the time we're reading these comments in the raw code, and all that XML marking makes things cluttered to read. But at least this one has a short element and attribute name.

@svick
Copy link
Contributor

svick commented Jul 7, 2016

Personally I don't like these wordy XML ways of referencing code types, most the time we're reading these comments in the raw code, and all that XML marking makes things cluttered to read.

I agree, but I think the solution would be to add a completely new non-XML syntax, instead of just improving one aspect of it. And that has already been proposed: #85.

@copernicus365
Copy link
Author

Great point, and thanks for the link to that other issue. That expresses my sentiments well:

XML Doc comments are verbose, ugly, and annoying to write and read, even with the IDE support Visual Studio provides. There's no reason human beings should have to be manually typing or reading XML.

Unlike that author I am not anti-XML, but in this case, for primarily human-readable documentation, it is a poor solution in my view. And how interesting it is that proposed solution uses the '@' symbol copiously as well. (I am influenced by Razor).

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

No branches or pull requests

2 participants