Writing Codesnippets to use in method chaining
Asked Answered
R

0

8

The Goal

Write codenippet which produces this result: .Select(k => new { })

The test snippet body

<Header>
    <Title>SelectAnonymous</Title>
    <Shortcut>selectAnonymous</Shortcut>
    <Description>Shortcut for creating Selects with an anonymous object.</Description>
</Header>
<Snippet>
    <Declarations>
        <Literal>
            <ID>ParamName</ID>
            <ToolTip>The name of the parameter</ToolTip>
            <Default>x</Default>
        </Literal>
    </Declarations>
    <Code Language="CSharp">
        <![CDATA[.Select($ParamName$ => new { $end$ })]]>
    </Code>
</Snippet>

The Probem

Visual Studio doesn't suggest using code snippets when chaining methods like this: dummyObjectList.selectAnonymous, it only suggest methods at that point.

The Question

Is it possible to "teach" Visual Studio or to alter the Code Snippet in such a way that Visual Studio would suggest using the snippet along side the existing methods (while chaining methods as described above)?

The Tech

Visual Studio 2019

The Struggle

Is Real

Radloff answered 4/12, 2019 at 12:56 Comment(8)
Plus one for "The struggle -- is real"Toro
bows politelyRadloff
I don't think you can do this, VS intellisense is context sensitive and only suggests snippets for a blank line.Ikon
@RonBeyer thanks for the input, I was affraid it might be like that :/Radloff
Is there a work around for that that you can think of?Radloff
As a workflow workaround, could you just use Ctrl+K, Ctrl+X to insert your snippet at the cursor?Expatriate
inefficient @Expatriate but not a bad work around indeed :DRadloff
might actually implement a ToDictionary code-snippet now Thaat might infact save time how often I have to do .Select(v => { key1, key2 } ).ToDictionary(k => key1, k => key2)Radloff

© 2022 - 2024 — McMap. All rights reserved.