Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-generate variable *name* to match parameter you're providing?

R# 4.5 (answers to 5 are welcome)
VS2008 (answers to VS2010 are welcome)
C# (FWIW)

I'm using a constructor (the question applies for methods, too), and there's Intellisense:

Foo Constructor Intellisense, showing the parameter variable names

I don't yet have a value to specify for this first parameter, "firstName". Today, I type "firstName", then let the IDE create that variable for me (which I initialize to some value).

I understand that the IDE will create the variable for me. I want it to create the variable name for me.

I don't want to have to type "firstName". I like the variable name the parameter author chose, and I want to use that variable name in my (calling) code.

Is there a way to have these acceptable variable names re-generated for me (the calling code) automatically as I move, parameter by parameter, through this line of (calling) code?

like image 393
lance Avatar asked Aug 18 '10 15:08

lance


1 Answers

You may get close to what you are looking for with VS2010.

  • Type p.Foo(

This will open the description of the currently selected constructor, out of the list of all constructors. If you type a letter, or hit ctrl + space, intellisense auto completion will open.

A difference here between VS2008 and VS2010 is named parameters. In VS2010, your completion list will have entries for the named parameters firstName: and lastName:.

  • Type the first letter of the parameter name (what you are referring to as "the variable name the parameter author chose")

Intellisense should jump straight to that entry, and allow you to do completion the same way it usually does.

  • Type a space, enter, or comma

Intellisense it will insert the identifier used for the named parameter. It won't insert the colon (unless you type it), so you don't have to use the named parameter feature to accomplish your goal here. You can just take advantage of the fact that the text you are looking for is in your completion list.

How you get Visual Studio to actually generate the local variables (which, according to your question, it seems like you have already solved) baffles me, and would be up to you to take care of :) If you've got that second problem licked, I'd like to know how, too.

like image 89
Merlyn Morgan-Graham Avatar answered Oct 09 '22 03:10

Merlyn Morgan-Graham