Visual Studio autocomplete event handler with lambda format

I am on VS2012 and want to use the lambda format for event processing, however VS does autocomplete using the tab key whenever you enter a substring of events through + =, for example:

VS autocompleted with reference to function a inserts the function:

txtTitle.TextChanged += txtTitle_TextChanged; void txtTitle_TextChanged(object sender, TextChangedEventArgs e) { .... } 

Is there a way to force autofill in lambda format:

 txtTitle.TextChanged += (object sender, TextChangedEventArgs e) => { .... } 

Its a huge pain that needs to be copied and pasted from autocompleted non-lambda to the more rigid lambda format.

+4
source share
2 answers

You can just create a piece of code, I have one for creating Lambda events.

Here is a snippet if you want to try (just save as whatever.snippet) and import into VS (Tools -> Code Snippet Manager)

Excerpt:

 <?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>SnippetFile1</Title> <Author>sa_ddam213</Author> <Description> </Description> <HelpUrl> </HelpUrl> <Shortcut>le</Shortcut> </Header> <Snippet> <Declarations> <Literal Editable="true"> <ID>s</ID> <ToolTip>s</ToolTip> <Default>s</Default> <Function> </Function> </Literal> <Literal Editable="true"> <ID>e</ID> <ToolTip>e</ToolTip> <Default>e</Default> <Function> </Function> </Literal> </Declarations> <Code Language="csharp" Kind="method body"><![CDATA[($s$,$e$) => { };]]></Code> </Snippet> </CodeSnippet> </CodeSnippets> 

Then to use just type eventname + = le Tab

Example

Uploaded + = tab

Result

 Loaded += (s, e) => { }; 
+4
source

You can write:

 this.txtTitle.TextChanged += (s, e) => {}; 
0
source

All Articles