Live Template: macro for suggesting paramter of several types

Hi

I'd like to write a macro that invokes a method and expects a parameter. The method has two overloads, one for string, the other for ICollection. Is there a way to specify a list of of possible types instead of just one.

A workaround would be to have two templates, requiring the programmer (me ;) ) to choose the type up front, aside from it being a violation of the DRY principle.

Regards, Michael

4 comments
Comment actions Permalink

Hello Michael,

You can also put caret inside parenthesis with $END$ built-in macro and then
invoke Smart Completion (default shortcut is Ctrl-Shift-Space), which should
do what you need.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


MK> Hi
MK>
MK> I'd like to write a macro that invokes a method and expects a
MK> parameter. The method has two overloads, one for string, the other
MK> for ICollection. Is there a way to specify a list of of possible
MK> types instead of just one.
MK>
MK> A workaround would be to have two templates, requiring the
MK> programmer (me ;) ) to choose the type up front, aside from it being
MK> a violation of the DRY principle.
MK>
MK> Regards, Michael
MK>


0
Comment actions Permalink

Hello Ilya,

Yeah, I guess that would work, except than I won't have the cool filtering of the available options. Especially if there is only one local variable matching the type in the macro.

The solution with two macros works, I guess. But I do believe I will revist the issue once I neet a macro for more than 2 overloads.

Regards, Michael

0
Comment actions Permalink

Hello Michael,

No, you won't miss the filtering. The key point is that you need to invoke
smart completion, which is ctrl-shift-space. It will suggest only items,
applicable in the current context. If it is only one variable (and you have
appropriate settings in ReSharper Options, Intellisense, Code Completion
for "Skip completion list with one choice"), it will be immediately put in
place. On the other hand, it is 3 more keys to press...

We will consider including smart completion invocation macro in the built-in
list.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


MK> Hello Ilya,
MK>
MK> Yeah, I guess that would work, except than I won't have the cool
MK> filtering of the available options. Especially if there is only one
MK> local variable matching the type in the macro.
MK>
MK> The solution with two macros works, I guess. But I do believe I will
MK> revist the issue once I neet a macro for more than 2 overloads.
MK>
MK> Regards, Michael
MK>


0
Comment actions Permalink

Hello Ilya,

I see. I guess I should have mentioned that I need the variable. It's for an argument check method I have to invoke with both the name of the parameter and the value.
For Example: Check ("parameter", parameter);
So I cannot just use the $END$ instead of an actual variable.

Regard, Michael

0

Please sign in to leave a comment.