How do I automatically generate documentation/comments in Monodevelop? - c#

Monodevelop automatically generates verbose documentation for functions and classes if "///" is typed in the appropriate place, upon typing the third '/'.
I want it to go over all of my code, though - I thought there was some button somewhere, and I looked around in the drop-down menus, tried right-clicking file names, etc.
I could not find such an option - does it not exist? I could not find a plugin that does that either.

Try to use Edit-> Document buffer.
It will make /// comments for all your public methods/classes without any comment upon it in current file.
It won't work if you have // comment upon method/class or for protected/private elements.

It is not possible. Your options are:
Manually typing three slashes before each and every function
Using an external tool
Online searches have not come up with any plugins for monodevelop that would do that, and the option does not exist in the vanilla IDE.

Related

What are regions summary comments in C# source code?

I know what is attributes in C#, but I don't know what are those text. I never see them in any C# language textbook.
Can you help me explain what is the text in the code?
What are their purpose? Can I safely delete them?
///
#region
#region
lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor. In longer code files, it is convenient to be able to collapse or hide one or more regions so that you can focus on the part of the file that you are currently working on.
https://msdn.microsoft.com/en-us/library/9a1ybwek.aspx
/// comments
In Visual C# you can create documentation for your code by including XML elements in special comment fields (indicated by triple slashes) in the source code directly before the code block to which the comments refer.
When you compile with the /doc option, the compiler will search for all XML tags in the source code and create an XML documentation file. To create the final documentation based on the compiler-generated file, you can create a custom tool or use a tool such as Sandcastle.
Also, Visual Studio intellisense will use this information to show to the consumer of your public APIs as description. Like if you have descriptions about an input argument, the comments you mention for that argument will be displayed to the user trying to call that function in Visual Studio like the image below:
The cooments xmldocs comments. You can safely delete them, if you want to, of course.
Regions are text "helpers" which help you to specify outlining of your code.
/// is for auto-generated documentation
Yes, it's safe to delete. Microsoft documentation here.
#region and #endregion can be safely deleted if you delete just these tags (not the code in between)
Yes both can safely be deleted without any damage to the code, so long as you delete just the #region and #endregion tags and not the code between.
Regions are just what the name implies, a region of code that does a specific thing, for instance in many controllers you see a Create, Read, Update, and Delete region, to define where the code for CRUD operations goes, this also allows you to collapse a whole region in VS and likely other IDEs as well, to better view only what you want to see, makes navigating code easier.
Three slashes /// are used to define the XML documentation on classes, properties and methods. VS has the option to output this on a build to an XML document, then there are other tools that can be used to make that XML easier to use. The summary also shows up as the tooltip when you hover over usages of those classes, methods and properties in VS, to make it easier to understand the function of the methods and classes without reading over the code.
Neither is actually vital to the code, but they are helpful to developers that are looking at the code, even the same person who wrote the code can get use out of XML comments when coming back to something they did months ago.

How to change formatting options based on solution

My boss set our IDEs up to use non-standard formatting. For example, it adds spaces between the parenthesis and parameters. This is fine for the new stuff that we've started from scratch, but it's super annoying when I go into existing projects and try to format the code with Ctrl-k-d because when I go to compare the file with the latest version before checking in my changes it looks like I've changed almost every single line in the file and it's difficult to pick out the actual changes.
I would like to be able to use his settings in the newer development, but switch to the default settings when working with other projects. Is there a way to accomplish this without having to go into the settings and uncheck/recheck all the appropriate options every time?
EDIT: I understand it might be good to reformat all legacy code to use the new standards. Unfortunately, that's not my decision to make. And even so, I sometimes work from my personal computer which I also use on occasion to do contract work for other companies. I obviously can't reformat their code to fit my bosses standards.
You can easily switch between settings, by creating separate .settings files and using a VSIX package to switch between them by loading them into Visual Studio - I use this for switching between Dual and Single monitor settings via menu items in the Tools menu.
Using an extension is annoyingly complex for such a simple operation, and this was a whole lot easier when Visual Studio supported macros. However I've uploaded my homebrew extension to GitHub in case you want to have a look.
The tricky bit is editing the settings files to only contain the ones you're interested in, which I expect are the ones in Text Editor\C#\Formatting\Spacing.
The Rebracer extension stores code formatting options alongside each solution and when you open a solution, Rebracer will automatically apply that solution's settings.

Enum Intellisense Display Attribute?

I want to do this:
enum Foo
{
[Display="Item One"]
ItemOne,
}
So that Intellisense will display it like in the attribute instead of the actual name.
I know it's possible, I've seen it before.
Well you could provide XML documentation:
enum Foo
{
/// <summary>Item One</summary>
ItemOne
}
I'm not sure whether that's quite what you were thinking of, but here's an example of what it looks like in VS 2010:
Note that I'm assuming you mean from the code editor... if you mean within a property editor, that could be something entirely different, e.g. DisplayNameAttribute (although that's meant for properties, events or methods).
If you know an example of what you want within the framework, we may be able to help more.
As a note... if you are building a .dll that is to be referenced by another application, just writing a summary will not allow the text to show up in intellisense for the referencing application. To accomplish this, you must deploy the XML documentation file as well, which requires a re-compiled version of the same .dll.
To do this (in VS2008 anyways), go into the Properties of your project, click the Build tab, click the checkbox at the bottom next to 'XML documentation file:', rebuild the application, and now you have the files needed to make it work.

ASP.net c#, how do I know what to use?

I keep coming accross code samples online for ASP.net c#, however they never seem to list which namespaces they include, for example:
using System.Data.SqlClient;
etc etc
Am I missing something obvious or should I be expected to know exactly what namespaces each code example requires?
When I'm in that situation, typically I search for the class on MSDN. The documentation will tell you which namespaces contain the class.
If they don't include them, you can follow this list in order:
Find that they are in one of the namespaces listed in the "blank code file" template , or
In Visual Studio You can click the missing type and press shift+F10 or Ctrl+. To get the option to automatically add the using statement (if the assembly is referenced)
With Resharper, Select the type and hit alt+enter for Resharper to find the namespace for you, and add it to the usings (possibly even reference the assembly as well)
Go to MSDN and search the name.
Go to Google and search the name (honestly, I normally do this before hitting MSDN anyway)
Compain to the article author
If code samples use the assemblies that a project references by default, then you can hover on the class name and click shift+F10 which will add the using statement automatically. If the class is not in any of the referenced assemblies then you are out of luck and need to know in what assembly does the class resides.
A quick google search can help, and in time you will memorize the namespaces... Of course its best if samples included the namespace and reference info, but mostly they do not.
If you are viewing code in Visual studio, just hover mouse over class or object you want and you will get tool tip about it if assemly of that class is present or you can google for particular class.For example if you want to know more about 'DataTable'class, just google it and you will come to know that its part of Syste.Data namespace.
I'm with the OP on this one. Having to just magically "know" what namespaces are required seems supremely silly.
I spent some time before C# as a Java Developer, and the NetBeans IDE will resolve these for you automatically. Ctrl-Shift-I, and it will insert all the packages (ie, namespaces) you need. If more than one package defines the class you are resolving, a window pops up and lets you choose which one you want.
For as fine a product as VS is, I am incredulous that this feature is not included.

Remove the automatic #region/#endregion tags when implementing an interface in Visual Studio 2005/2008

When user the "Implement Inteface X" context menu feature, the inserted code gets surrounded by a
#region [interfacename] Members
#endregion
pair. I always end up deleting this, is there a way I can permanently turn it off? I had a quick search through the snippets directory, but wasn't sure if this was the right place. There's pp_region.snippet that I guess I could modify, but I got the feeling that would turn off the #region/#endregion completely. I thought I'd ask here before I go doing things that will have me re-installing VS...
You can turn it off via Tools / Options
Then, in the option-window, you select 'Text Editor', then the language of your choice (C# for ex).
Then, you select 'Advanced', and then, you have a checkbox which says:
'Surround generated code with #region'
Also, if you're using Resharper you can fully configure the layout of your classes so they'll look exactly the way you want. One of the options is to completely remove the region tags whenever it finds any. It's awesome to open any c# project and have it reformatted just by doing [CTRL+E, C]

Categories