7

How can I document a member inline in .Net? Let me explain. Most tools that extract documentation from comments support some kind of inline documentation where you can add a brief after the member declaration. Something like:

public static string MyField; /// <summary>Information about MyField.</summary>

Is there a way to do this in C# or the .NET languages?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Curro
  • 832
  • 2
  • 10
  • 14

3 Answers3

7

No, you can't. XML comments are only supported as a block level comment, meaning it must be placed before the code element you are documenting. The common tools for extracting XML comments from .NET code do not understand how to parse inline comments like that. If you need this ability you will need to write your own parser.

Scott Dorman
  • 42,236
  • 12
  • 79
  • 110
2

There is not a built-in way to do this. The XML documentation system is hierarchical; it defines a relationship between the tag <summary /> and the data that immediately follows it.

Robert S.
  • 25,266
  • 14
  • 84
  • 116
1

Yep, just put it BEFORE the thing you want to comment

/// <summary>Information about MyField.</summary>
public static string MyField; 
GeekyMonkey
  • 12,478
  • 6
  • 33
  • 39
  • I know I can put it before. I'm asking if I can put it after in the same line. – Curro Nov 06 '08 at 15:13
  • That's not an inline comment. – Scott Dorman Nov 06 '08 at 15:13
  • // specifies an inline comment as opposed to /* for multiline This is what I thought you meant. No, there is no way of putting it AFTER. How would the compiler know you didn't want to apply it to the following line? – GeekyMonkey Nov 06 '08 at 15:33
  • Most parsers use a character to understand that the documentation is referring to the symbol prior to the comment. Something like: public static string MyField; //- Information When the parser sees //- as opposed to /// it knows it is documentation for the preciding symbol. – Curro Nov 06 '08 at 16:27
  • It's perfectly simple: A comment appearing after code *on the same line* refers to the preceding code. But no, this isn't supported with XML comments. – Ian Goldby Mar 12 '15 at 10:09