Is there a snippet for an auto-property in VB.NET? - vb.net

In Visual Studio 2010, for VB.NET, the "Property" + Tab + Tab inserts a full property implementation. Is there another snippet for inserting an autoproperty?

Just put this in a file called C:\Users\\Documents\Visual Studio 2010\Code Snippets\Visual Basic\My Code Snippets\DefaultProperty.snippet and restart VS... or put it in that file but not in that dir, then in VS click Tools, Code Snippets Manager, and Select Visual Basic as the language... the click on the Import button. Select your new file, and then choose the top folder "My Snippets". Now in the IDE just type PropDefAuto and tab tab. Feel free to modify the file.
<?xml version="1.0" encoding="UTF-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Define a Auto-Implemented Default Property</Title>
<Author>Some Guy On SO</Author>
<Description>Defines an Auto-Implemented default property or index property.</Description>
<Keywords>
<Keyword>PropAuto</Keyword>
</Keywords>
<Shortcut>PropDefAuto</Shortcut>
</Header>
<Snippet>
<Imports>
<Import>
<Namespace>System</Namespace>
</Import>
</Imports>
<Declarations>
<Literal>
<ID>propertyName</ID>
<Type>
</Type>
<ToolTip>Rename to descriptive name for the property.</ToolTip>
<Default>PropertyName</Default>
</Literal>
<Literal>
<ID>indexType</ID>
<Type>
</Type>
<ToolTip>Replace with the type of the index</ToolTip>
<Default>Integer</Default>
</Literal>
<Literal>
<ID>propertyType</ID>
<Type>
</Type>
<ToolTip>Replace with the type returned by the property.</ToolTip>
<Default>String</Default>
</Literal>
<Literal>
<ID>IndexIsValid</ID>
<Type>Boolean</Type>
<ToolTip>Replace with an expression to test if index is valid.</ToolTip>
<Default>True</Default>
</Literal>
</Declarations>
<Code Language="VB" Kind="method decl"><![CDATA[Public Property $propertyName$ As $PropertyType$
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

The closest you can currently get in VB is typing out
Property Name as string
You can find more information in this blog post by The Gu

Related

vsto repurpose font comboBox

I'm trying to repurpose the built in font selector for my own objects in PowerPoint (vsto add-in). I repurpose regular commands (bold, italic etc.) successfully using the ribbon xml.
I have a test that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab idMso="TabAddIns" label="Test">
<group id="MyGroup"
label="My Group">
<comboBox idMso="Font" label="ComboBox1" onChange="ChangeCallback"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
If I have a regular is instead of the idMso this callback works fine:
ChangeCallback(Office.IRibbonControl control, string text)
{
Debug.WriteLine("Changed");
}
The callback stops working when I use idMso="Font", but the comboBox works and I can use it to select font like normal.
I have tried the following callback with no luck.
ChangeCallback(Office.IRibbonControl control, string text, ref bool cancelDefault)
{
Debug.WriteLine("Changed");
}
When I repurpose commands I put it in the commands section of the xml instead of the ribbon, but having a comboBox element there is not allowed.
Any ideas on how to get this to work?

How can I configure a live template that generates a builder method in IntelliJ IDEA?

I oftentimes need to create builder methods in my code. These methods are similar to getters, but they return this and they use with instead of get.
To be faster with that task I'd like to create a live-template in IDEA.
This how far I got:
(in ~/.IntelliJIdea14/config/templates/user.xml this looks like this:)
<template name="builderMethod" value="public $CLASS_NAME$ with$VAR_GET$(final $TYPE$ $PARAM_NAME$) {
this.$VAR$ = $PARAM_NAME$;
return this;
}" description="create a builder method" toReformat="true" toShortenFQNames="true">
<variable name="CLASS_NAME" expression="className()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR" expression="complete()" defaultValue="" alwaysStopAt="true" />
<variable name="PARAM_NAME" expression="VAR" defaultValue="" alwaysStopAt="true" />
<variable name="TYPE" expression="typeOfVariable("this." + VAR)" defaultValue="" alwaysStopAt="true" />
<variable name="VAR_GET" expression="capitalize(VAR)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_EXPRESSION" value="false" />
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
This nearly works, except for typeOfVariable("this." + VAR) which does not. I just guessed how to call this method, because I could not find any documentation on the syntax used in the expressions except for this page which does not even mention a script language name or something that would make googling for easier.
How do I fix the call to typeOfVariable?
Bonus question: How can I get complete() for VAR to only show fields?
Similar question but not does not even have a start: Live Template for Fluent-API Builder in IntelliJ
Replace typeOfVariable("this." + VAR) with typeOfVariable(VAR).
Edit:
Another way to generate builder methods is to use an appropriate setter template (instead of live template).
https://www.jetbrains.com/help/idea/2016.1/generate-setter-dialog.html
There is already a built-in setter template named "Builder" which generates setters such as:
public Foo setBar(int bar) {
this.bar = bar;
return this;
}
You can create your own template (e.g by copying it) and change it so that the method prefix is with.
And to make the generated method parameter final go to settings:
Editor | Code Style | Java
Select the Code Generation tab
Tick Make generated parameters final
IntelliJ IDEA add final to auto-generated setters

Visual Studio 2010 insets code snippet code on new line

Assuming I want to create a code snippet for ToString(), I have created the following snippet:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>To String VB</Title>
<Author>John Doe</Author>
<Description>Shortcut for ToString()</Description>
<Shortcut>ts</Shortcut>
</Header>
<Snippet>
<Code Language="VB">
<![CDATA[toString()]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
When I write the code myObject.ts and then press tab to invoke the code snippet, visual studio does this:
myObject.
toString()
instead of this:
myObject.toString()
How can I keep the snippet completion on the same line that I invoked it from? I came across a page that mentioned using $end$ to mark the position the cursor should go when the snippet is inserted, but that has done nothing for me besides including the $end$ in the snippet.

Expanding multi-line snippet adds extra line at the bottom

Is there any way to prevent the addition of an extra line below a multi-line snippet in VB.NET?
(hit tab key to expand snippet...)
I've double checked that the snippet itself does not have an extra line at the end. Also, this seems to be VB-specific.
Just close the ]] after the end of your snipped. The ¿end¿ part sets the caret at this position after inserting the snipped.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>tryt</Title>
<Author>[USERNAME]</Author>
<Description>
</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>tryt</Shortcut>
</Header>
<Snippet>
<Code Language="vb" Delimiter="¿"><![CDATA[Try
¿end¿
Catch ex As Exception
Throw New Exception(ex) 'or do some other stuff
End Try]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

How do you automatically tab ALL the selected text when using a SurroundsWith SnippetType?

Below is my SQL snippet that is used to surround existing SQL. After highlighting some SQL and inserting this snippet, I want ALL the selected text to be indented by a tab or several spaces. My snippet currently will indent just the first line of highlighted code.
How can I make is indent all the selected text?
Here is my SQL snippet.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Insert a comment header for SQL</Title>
<Shortcut>header</Shortcut>
<Description>SQL Snippet will add comment area for header to break up code</Description>
<Author>Mike Adams</Author>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>headerText</ID>
<ToolTip>Header Text</ToolTip>
<Default></Default>
<Function></Function>
</Literal>
</Declarations>
<Code Language="sql">
<![CDATA[
-- $headerText$
---------------------------------------------------------
$selected$
$end$
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>