Stop auto adding "///" in XML Doc Comments. (C#) - c#

How do I stop Visual Studio from automatically adding "///" in XML documentation comments when adding new lines.
For the following examples the '|' character stands for the cursor position.
For example when pressing enter at this line:
/// Some comment |
Is automatically enters "///" at the beginning of the next line:
/// Some comment
/// |
What I want is simply this:
/// Some comment
|
How do I make this happen?

The triple slash pattern is a shortcut to invoke the VS XML documentation feature set. If you don't want that behavior, you could just use the more conventional double slash pattern; it won't produce automatic insertions on new lines.

Related

Regular expression behaves differently in Find in Files and in Search current file

I'm trying to find all strings in my code, while excluding stuff like AssemblyInfo.cs files, comments and XML content.
I've come up with a regular expression which works when I use it with Ctrl+F, however when trying to use it with the "Find in Files" dialog (Ctrl+Shift+F), it delivers an arbitrary result, including even empty lines and lines which only contain e.g. an opening curly brace {.
Is this a bug in VS2013? I unfortunately don't have other versions available to test this behavior.
Here is the regular expression and its explanation:
^[^\[/<]*\".*\"
^: Start of line
[^\[/<]*: Any amount of characters which are not [, / or <
\".*\": Any amount of characters enclosed by two quotation marks
When using it with the regular search (Ctrl+F), this properly detects lines like
"This is a test"
someObject->doSomething("This is a test");
and intentionally does not detect lines like the following:
[assembly: AssemblyTitle("....")]
/// <param name="Test">Test</param>
However, when I'm using the "Find in Files" dialog, the same expression lists the full implementation of some methods including lines with only braces, class definitions and empty lines.
Do I have to use a different syntax or anything with Find in Files, or does it not support the same features as when searching within one file?
[Edit:]
Note that leaving out the [...] expression works as intended in both search dialogs
[Edit2:]
VS Version is "Microsoft Visual Studio Professional 2013, Version 12.0.30723.00 Update 3"
The regular expression part [^\[/<]* apparently matches line breaks in the "Find in Files" dialog, unlike the regular Find dialog.
The problem can be solved by explicitly excluding \n both in this part of the expression and between the quotes:
Full Expression: ^[^\n\[/<]*"[^\n]*"
The (?m) modifier is probably not supported by Visual Studio 2013, it seems to be ignored, at least in this example.

Number of asterisks starting a C# comment block

In a C# program in Visual Studio 2010 I have a large, multiline comment block starting with
/**
Part way through the comment block is a line that looks like this . . .
this.afIODisplay = "<" + lineToParse + Environment.NewLine +
this.afIODisplay;
At the point of the less-than symbol the color changes from comment-green to gray and the compiler issues a warning saying
XML comment on 'xxxxxxxxxxxxxxx' has badly formed XML -- 'A name was
started with an invalid character.'
(xxxx's replace proprietary code identifier) Why is the compiler trying to interpret the comment block as XML?
As an experiment I tried escaping the less-than symbol with
&lt
but that didn't fix it; it just replaced the warning with a new one saying
A name was started with an invalid character
and eliminated the transition to gray. I then replaced the starting line of the comment block with
/*
and the problem went away!! It also stayed gone with a whole line of asterisks. Why do the number of asterisks matter in C# comments? Or is this just a Visual Studio bug?
You have malformed XML in a documentation comment. This generates a warning according the specification. In Appendix A of the C# 5 spec:
Comments having a special form can be used to direct a tool to produce XML from those comments and the source code elements, which they precede. Such comments are single-line comments that start with three slashes (///), or delimited comments that start with a slash and two stars (/**).
and
The text within documentation comments must be well formed according to the rules of XML (http://www.w3.org/TR/REC-xml). If the XML is ill formed, a warning is generated and the documentation file will contain a comment saying that an error was encountered.
multiline comment in c# starts with /*
/** is used for XML comments

How can I automate the removal of XML Documentation Comments?

Does someone have a script or snippet for Visual Studio that automatically removes comment headers for functions or classes?
I want to remove comments like.
/// <summary>
///
/// </summary>
Actually anything that removes comments starting with /// would really help. We have projects with massive amount of GhostDoc comment that really just hides the code and we are not using the document output. It is a tedious work for us to remove theese comments.
Open Quick Replace (CTRL + H) in Visual Studio and replace :b+///.*\n with an empty string (ensure you set Use to Regular expressions). This should allow you to get rid of the comments in the specified scope.
You can use this Regex \/\/\/.*<summary>.*<\/summary>, with these options gms, to match the string. You can replace that with nothing. This can be done in Notepad++ or Visual Studio.
Here is a Regex 101 to prove it.
You can use Python (with regexps, if you wish):
#! /usr/bin/python
import sys
if len(sys.argv) < 2:
print( "Usage: removelines <source-file>" )
exit(0)
InFileName = sys.argv[1]
Out = open( InFileName + ".out", "w" );
for Line in open( InFileName ).readlines():
if Line.lstrip().find( "///" ) == 0:
print( "Skipping line", Line )
continue
Out.write( Line )
You could use find and replace in files in Notepad++ (or any other advanced text editor) using regex.
You can just do find and replace with an empty string in visual studio. You already have the strings you want to get rid of. You could also parse the code files as text and remove any line that starts with a comment character.

How do you add a blank commented line in T4 using Ghostdoc Pro in Visual Studio?

Inside of the "Rules" settings in GhostDoc Pro it allows me to use T4 to format my comments. However it randomly adds line breaks(which I have sorted out), and also will not allow me to add a single line of triple forward slashes.
For example:
///======================================================
///Class: TripleSlash
/// //<-----How do I add just a blank line like so?
///<summary>
/// Class of the triple slashing breed
///</summary>
///======================================================
I have tried adding a StringBuilder.Append("///"); I have tried just simply adding the three slashes. However it seems that GhostDoc Pro removes any line of T4 or C# code that would add a blank triple forward slash commented line.
I feel like I'm overlooking something simple.
T4 for Ghostdoc does not support inserting a line break or a blank line.
sad day.

Add special carriage return characters using a code snippet in VS

I would like to create a code snippet that produces a double slash between to marks.
For example I write one that produce
//>
Cursor ready to edit
//_
This is useful but i want
//>
// Cursor
//_
And if I end a line between this two marks I want that the snippet create immediately two more slashes
//>
// line terminated with an Enter
// Cursor
//_
What I need is something similar to what exist with the 3 slash mark that creates the special commentary blog.
/// <summary>
/// text terminated with an Enter
/// Triple slash automatically added
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
Is that possible to be created?
If you have reached the limits of what snippets can do, you might want to try macros. Visual Studio includes several text editing macros in the samples to get you started. Tools -> Macros -> Macros IDE -> Samples -> VSEditor. For example NewCommentLine(). Copy it to MyMacros and adjust to your needs, and then assign it to a key sequence or toolbar.

Categories