Class highlighting in documentation comments - visual-studio

I am using MS Visual Studio 2015 and I am trying to do some documentation and description of methods I made. I use the /// comment and would like to highlight exception class names in IntelliSense popup. So I would like to get result like ... does fancy things and sometimes blows with DivideByZeroException, because you are not Chuck. with DivideByZeroException being with the same color as classes usually are in the body of summary text. Seen the picture below.
How this can be reproduced, please? I tried to look into MSDN database, but I didnĀ“t managed to find a way (if it can be done).

Preface: I am the asker of this question, so this is the reason of "me-style" answer :-)
I had recently looked into this and it seems as it cannot be done as I was hoping. According to this post on SO, and this MSDN documntation, the behaviour I was hoping to reproduce in the bulk of summary text is a speciality of exception documentation tag:
<exception cref="DivideByZeroException">Thou' are not Chuck</exception>
what might do the trick is <c> or <code> tags. Unfortunately, they do not seem to do anything in my VS2015 Express IntelliSense, so I cannot verify this.

Maybe you can do it like below.
/// <summary>
/// ... does fancy things and sometimes blows with DivideByZeroException, because you are not Chuck.
/// </summary>
/// <exception cref="DivideByZeroException" />
I am using VS2015 community edition.

Related

Is there any way to find the C# code that is created from XAML with Xamarin?

Given some Xaml like this:
<headingView:HeadingView
x:Class="Test.Views.Decks.DeckBase.DeckMgmt.DeckMgmtPage2"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:headingView="clr-namespace:Test.Templates.Pages.HeadingView;assembly=Test"
xmlns:t="clr-namespace:Test.Templates"
BackIconVisible="True"
PageTitle="Mgmt">
<t:Stack>
<t:ContentFrame Heading="Reset">
<t:LinkGrid TapCommand="{Binding ResetDeckCmd}" Text1="Reset" />
</t:ContentFrame>
<t:ContentFrame Heading="Sort">
<t:LinkGrid Text1="Sort" />
</t:ContentFrame>
</t:Stack>
</headingView:HeadingView>
I don't need help in changing this to C# but I would like to know if there is any place or way I can find out the intermediate C# that is created?
Viewing the actual code generated by the compiler is tricky (I tried for a couple of hours but I could not find a way to directly view the code) - but it is possible to view the source code itself.
First of all - download .NET reflector and the appropriate Visual Studio extension.
https://visualstudio.microsoft.com/vs/preview/
Now we need to find the method that we want to decompile.
The method Xamarin.Forms.Xaml.Extensions.LoadFromXaml() is found in your page's xaml.g.cs file. According to Microsoft:
When Visual Studio builds a project containing a XAML file, it [the method] parses the XAML file to generate a C# code file (for example, MainPage.xaml.g.cs) that contains the definition of the InitializeComponent method:
The method in this case is the LoadFromXaml() method.
Now add a breakpoint like so:
Press F12 until you reach the following:
You will reach the 'Load' method:
You will see something like this:
From here - you can browse the rest of the XamlLoader class's source code:
Very interesting, isn't it? This is the closest thing to a solution that I got to.
I've just shared it as an image as I don't think it would be appropriate to share the full code as a code snippet.
It's not exactly what you're looking for - but I still hope this helped answer your question either way.

Comments only visible in same Project - Visual Studio 2013

well the title says everything. I've got a class with some comments in it.
Something like
/// <summary>
/// Bla
/// </summary>
The problem is, I can only see those comments inside the project. If I make an reference to this class and use it in an other project, the comments are not visible...
If the project is in the same solution, you can replace the reference with a project reference (the Solution tab in Add Reference).
If not, you need to open Project Properties in the original project and check Generate XML Documentation File in the Build tab.

How to change the z-order of classes in the Visual Studio Class Designer?

Maybe I am misunderstanding what the Class Designer in Visual Studio was intended for, but I am really struggling with expanded classes being displayed behind other classes on the canvas.
I would like to have two collapsed classes, one above the other. Then when I expand the class above it should display above the class below, so that the class below does not obstruct the members of the class above.
I realise that adding my classes in the right order will do this, but I don't want to re-add all controls when I want to change layout. Where is the "Send to Back / Send to Front" button??
Not sure this is still an issue but I just had a similar problem when visualizing things in "UML-like" structures in VS 2013.
I found that a more or less simple way might be to change the order in the .layout file:
The example hopefully shows how to do:
First example - Action is "under" the Object:
<actionShape Id="..." absoluteBounds="..." customColor="...">
<opaqueActionMoniker Id="..." LastKnownName="Action1" />
</actionShape>
<objectNodeShape Id="..." absoluteBounds="..." customColor="White">
<objectNodeMoniker Id="..." LastKnownName="Object" />
</objectNodeShape>
Second Example: I changed the order. The Action is above the Object:
<objectNodeShape Id="..." absoluteBounds="..." customColor="White">
<objectNodeMoniker Id="..." LastKnownName="Object" />
</objectNodeShape>
<actionShape Id="..." absoluteBounds="..." customColor="...">
<opaqueActionMoniker Id="..." LastKnownName="Action1" />
</actionShape>
I know, this is probably not the best way to do but it's the best I found.
Hopefully it helps to anyone.
Sorry for digging up an old post, but from the looks of it there aren't any such buttons, nor have they been added in Visual Studio 2012. Based on what I found in the MSDN forums here, this has been brought up before. I'm not sure if either of the posters in that thread actually went on to add the suggestion in Microsoft Connect, since it seems to be all VS 2012 now, but I've added a request for it here. Hopefully they get around to it eventually.

Is there a way in Sublime Text 2 to support JavaScript completion of objects/functions defined in other files?

If I am editing a .js file in Sublime Text 2 that makes use of a library defined in a separate .js file, is there a way to support tab completion of objects/functions defined in the external library file?
Something analogous to the following from Visual Studio:
/// <reference path="/js/some-library.min.js" />
which enables IntelliSense over the library/plugin code.
I haven't tried it myself yet, but there's SublimeCodeIntel: https://github.com/Kronuz/SublimeCodeIntel#readme
The OP in this thread: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=5319 seems to be complaining that it's pulling suggestions from outside the current file, which may mean it's doing what you want.
I was looking for the exact same thing, and I can confirm that SublimeCodeIntel works well. However, Sublime Text seems slightly less responsive when using SublimeCodeIntel, which is a drawback.
Another cool thing coming from a Visual Studio environment is the support for "Go to definition" in this plugin.
Another option is TernJS:
http://emmet.io/blog/sublime-tern/
I haven't yet used it, but it looks promising. Editor slowdown seems to be an issue with any code completion plugin; sounds like authors are still working out kinks in scraping and caching related files for code completion. The TernJS page addresses this issue and offers some config options for managing how it handles related files.

Visual Studio XML summary comment on single line

In Visual Studio, how do I change the default XML summary comment snippet from three lines to one line?
Currently it provides this snippet when I type ///:
/// <summary>
///
/// </summary>
I would like this shorter snippet:
///<summary></summary>
My summaries are often brief and the extra 2 line are unnecessary.
Is there a configuration setting for this or some customizable code/custom addon to fix this.
This is an older question, but I liked Jason Williams's suggestion of creating a snippet for this, so I did. Not very complicated, but copy-and-paste is even easier :)
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Single line summary</Title>
<Shortcut>summary</Shortcut>
</Header>
<Snippet>
<Code Language="csharp">
<![CDATA[/// <summary>$end$</summary>]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
You can change the shortcut by (probably obviously) changing the <Shortcut> value.
Paste that into a new file named SingleLineSummary.snippet and save it in the folder %USERPROFILE%\Documents\Visual Studio 2012\Code Snippets\Visual C#\My Code Snippets (modify to fit your version of Windows and Visual Studio).
If you're not familiar with snippets, to use this just put the cursor above a method/property/etc, start typing summary, and then hit TAB a couple of times.
Personally, I think this should be part of the VS editor itself. I know it's been requested in the past. In the meantime, the snippet idea is a good one, but the behavior is slightly different. If you want to keep the same behavior and if you are willing to purchase a 3rd party add-on, then SubMain has a product called "GhostDoc Pro" that, with a little bit of effort, will do this for you. (Note that they have a free, non-"pro" version, "GhostDoc", but I don't think it will work.)
If you want to go this route, here's how it works.
After installing GhostDoc Pro, go to your Tools menu. At the top will be a new fly-out submenu, "GhostDoc Pro".
Go to Tools -> GhostDoc Pro -> Options -> Rules
You will need to edit the T4 template for EACH type that you want this to take effect on.
Click on the rule and then hit "Edit"
At the top, modify
/// <summary>
///<# GenerateSummaryText(); #>
/// </summary>
to be just
/// <summary><# GenerateSummaryText(); #></summary>
In the method GenerateSummaryText, modify each this.WriteLine to be just this.Write
Hit OK to save, move on to the next template.
Before closing the options page, head up to "General" (from "Rules") and check the "Highlight auto-generated summary when Document This". This will cause the newly inserted auto-text to be selected off the bat so if you don't like it, you can just start typing. Of course, if you prefer to have the text just not generated at all, then you can do that, too, but you will have to modify the T4 templates a bit more. Specifically, you'll need to have GenerateSummaryText just use a single line,
this.Write(Context.ExecMacro("$(End)"));
This will have it not generate any text, but will put the cursor between the 2 <summary> tags.
Side Note:
If anyone knows of a way to get ReSharper or other add-on tools to do this, I'd be interested in seeing that solution as well--if for no other reason than just curiosity.
You can manually format the comment however you like it, as long as it remains valid xml.
The cheapest approach might be to disable the automatic comment-building action in Visual Studio (Tools > Options > Text Editor > C# > Generate XML Documentation comments for ///) and use a code snippet to insert /// <summary></summary>.
If you want the default format to be a single line, and/or help to keep the format tidy and readable, my addin Atomineer Pro Documentation may also be of interest. Among the many options is one to use a compact 1-line format for any comment that is short enough to fit on a single line. It is specifically designed to do this, so it may work better for your needs.
A final suggestion is that there are several other add-ins (Resharper, etc) that can generate simple boilerplate xml doc-comments - I believe some of these addins can be configured to use a particular text snippet. If you already have such an addin, it may be that yours can be adjusted to provide the one-line format you require, in a slightly more advanced manner than is possible with the basic Visual Studio tweak suggested above.
I was trying to do this today. I couldn't find a way to change it to happen automatically, so I figured I could do it afterward with find and replace and regex. It isn't a good answer to this question, but it doesn't appear there is a good answer and all the answers are workarounds. This is a good work around.
VS with Regex
Find: (/// <summary>)\r\n\s*///\s*(.*)\r\n\s*///\s*(</summary>)
Replace: $1$2$3
Notepad++ with regex
Find: (/// <summary>)\r\n\s*///\s*(.*)\r\n\s*///\s*(</summary>)
Replace: \1\2\3

Resources