Is there a way to create custom shorthand's in Visual Studio 2017.
Just like ctor or prop?
I would like to create a shorthand for unit-tests, to just type in for instance test and then having a predefined function to edit like:
public void Method_Condition_Expected()
{
// Arrange
// Act
// Assert
}
As #Peter B has suggested for Visual Studio itself you can do it with Snippet Designer (Tools->Code Snippets Manager).
I found out right now, that my installed Tool ReSharper (2016.3) has an option to create so-called Live-Template's.
With that, I can create a Template like this:
public void $Method$_$Condition$_$Expected$()
{
// Arrange
// Act
// Assert
}
The nice part is now, that i can tab through Method,Condition and Expected and overwrite the values.
How to use: Mark a Code-Area such like the code Above in Visual Studio then click on Resharper->Tools->Create Live Template from Selection->Create and Edit.
Now wrap code-areas for tabing through with $ for instance like $Method$ and give a shortcut name such like test.
I hope this helps somebody else as well.
For a closer Comparision between Visual Studio Snippet Manager and Resharper Live Templates see Difference between Live Template and Visual Studio Snippet
Related
In Visual Studio, is it possible to create hyperlinks inside source files that jump to a specific line of a file? I want to create a link to a specific line, like this:
// [[#DoStuff|Clicking here will take you to the method "doStuff."]]
//
//
//
//
// #DoStuff
//clicking the hyperlink should jump to the line above.
function doStuff(){
}
Is there any way to create hyperlinks in the comments that will jump to a specific method?
It looks like there's a Visual Studio plugin called HyperAddin that can do this. Unfortunately, it looks like it's only available for Visual Studio 2005 and Visual Studio 2008.
I frequently use the Show Smart Tag shortcut in Visual Studio 2010 (Ctrl + Period) when I want to generate using statements, implement interface methods, generate classes, etc.
I recently introduced this shortcut to my co-workers, and they love it.
Obviously, there is a host of contextual uses for this shortcut, and I feel like I've yet to find them all. Is there a central list of all the smart tags that come built-in with Visual Studio 2010? Or, is there a way for me to actually look at a list of smart tags that Visual Studio 2010 has loaded?
Thanks,
Tedderz
There is nothing in the Visual Studio UI which will display the set of possible smart tags. You listed MEF in your tags though. If you are working with a MEF compontent it's very easy to query for this information at runtime. Simple import all uses of ISmartTagSourceProvider and query for the Name attribute
[ImportMany]
public List<ISmartTagSourceProvider> SmartTagProviders;
void GetNames()
{
foreach (var provider in SmartTagProviders) {
var attrib = (NameAttribute)provider.GetType().GetAttribute(typeof(NameAttribute));
attrib.Name;
}
}
There is this nice program that enable you to easily create code snippets. I already managed to create snippets but it will be nice if the snippet where to show up in visual studio's intellisense.
For example visual studio already has several built in code snippets such as the one for creating the constructor of a class:
note that it was really easy and fast to use it.
On the other hand when I create my custom snippet with the program that I provided on the first link, these are the steps that I have to do in order to use it:
on step 3 I have to select the folder where the snippet that I created is located then on step 4 locate it.
It will be nice if I could use the code snippet that I created just like the ones that visual studio provides like the constructor one that I showed on the first image. Maybe if I place the snippet that I just created and place it where visual studio store the built in onces it works.
I had to add a shortcut to the snippet.
after adding the shortcut it appears on the intellisense without having to navigate to the folder where it was located by pressing ctrl+k and ctrl+x
I can simply insert code snippet for the Console.WriteLine(); by just using the cw with Tab + Tab. But I'm not able to find the same option for the Debug.WriteLine();.
I want to know how can we customize the code snippet template in Visual Studio for Windows Phone?
In Visual Studio 2010 (and assuming other versions as well), there is not a snippet for Debug.WriteLine(). In that case, you'll need to create a custom snippet. Fortunately, it isn't that hard with the available resources:
MSDN: Creating and Using IntelliSense Code Snippets
The Snippet Editor
Snippet Designer (Visual Studio Extension) and the related CodePlex Site
If you're using ReSharper, then Code Templates and specifically Live Templates are a quick and easy option.
Let me elaborate, since the title was a little rough. I have been looking for a way to make a WCF service work with Silverlight for days now. Eventually I come across a mention of something called a 'Silverlight-enabled WCF service'. The only problem is, this doesn't exist in my Visual Studio 2010 (and I have looked).
Someone then asked me whether it appears in Program Files(x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Silverlight\1033. Well it looks to be - there is a file called SLWcfService.zip.
Assuming this is the template I'm looking for, how do I get Visual Studio to add this to the list of item templates that I get when I select a new project?
Thanks.
I don’t about your specific case, but if you have an item up on VS and you want to save it as a template: Click on: File -> Export Template -> and then select Item Template.