简体   繁体   中英

Is there any shortcut to add the lambda/func arrow operator => in Visual Stuido 2019?

It's really a simple thing, ReSharper did it for me when I was writing a lambda expression, but I stopped using ReSharper and would like to know if there is any way to auto-complete a lambda or func operation with the =>

builder.HasKey(m => m.Id);

Following the @Sajeetharan tip, I created this snippet, but I would like to use it in a more simple way, I need to press tab 2 times and after that press enter, I'm not sure if it is efficient at all, almost returning to resharper for these little things

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>lambda</Title>
            <Shortcut>lambda</Shortcut>
            <Description>Code snippet for lambda</Description>
            <Author>Nestorzin</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                  <ID>Name</ID>
                  <Default>r</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp"><![CDATA[$Name$ => $Name$$end$]]>
            </Code>         
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

There is NO shortcut available. Certainly you can define one code snippet and insert,

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>lambda</Title>
            <Shortcut>lambda</Shortcut>
            <Description>Code snippet for lambda statement</Description>
            <Author>Bestorzin</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
                <SnippetType>SurroundsWith</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Code Language="csharp"><![CDATA[(() =>
    {
        $selected$ $end$
    });]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

And save it on

C:\YourName\Documents\Visual Studio 201?\Code Snippets\Visual C#\My Code Snippets

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM