views:

449

answers:

3

I have a class that contains a load of properties that contain results of some calculations e.g:

public class Results
{
    public double Result1 { get; set; }
    public double Result2 { get; set; }
}

In a different class I am doing calculations to populate the above properties, e.g:

public class Calc
{
    private Results Calc()
    {
        Results res = new Results();
        res.Result1 = ... some calculation
        res.Result2 = ... some other calculation

        res.Result3 = ... // not yet defined in 'Results' class
        return res;
    }
}

When I am writing the Calc class, 'Result3' will be highlighted in red as it is not yet defined in the 'Results' class.

Currently I am using the Resharper ALT-Enter shortcut, selecting "Create Property 'Result3'" which will create the following code int the 'Results' class:

public double Result3
{
    get { throw new NotImplementedException(); }
    set { throw new NotImplementedException(); }
}

Which I need to manually change to:

public double Result3 { get; set; }

Then I use the CTRL-Shift-Backspace shortcut to take me back to the 'Calc' class.

How can I easily create automatic properties in the 'Results' class if they are not yet defined directly from the 'Calc' class?

+1  A: 

As soon as you've pressed Alt-Enter to create the property, and then Enter to accept the data type, you actually get a drop-down list of ways of implementing it if you're on a recent version of ReSharper. One of them is auto property.

David M
I am using Resharper 5 and I only see four options when I Alt-Enter on it:create field ...create property ...Change all ...Change all local ...
Piers Myers
Yes. Create property. Then it creates it and takes you to it. The data type will be highlighted. Press enter to accept the data type. Then you see the choice of property implementation.
David M
Ah, I see that now, thanks for highlighting that feature. I can use it to remove one step. Would still like to do this all in as few key presses as possible.
Piers Myers
Alt-Enter, Enter, Down, Enter - that's 4...
David M
Hmm, I seem to have to do: Alt-Enter, Down, Enter, Tab, Down, Down, Enter - 7 steps :)
Piers Myers
Ah, you might be right. On the Mac at the moment...
David M
A: 

For Resharper 4/5, type prop then tab, then fill in the required parameters.

Neil Barnwell
I know about the 'prop' template but that means I have to go to the Results class and create it manually. I want to be able to do this as I am writing the Calc class.
Piers Myers
+1  A: 

Sounds like you'd like to stay in the Calc class and create your properties in Results in one go.

Here's what you do.

  1. Turn on Solution-wide error checking (Resharper 5 is considerably better/faster)
  2. Edit Calc referring to all Results properties, leaving the errors reported.
  3. Hit ALT+SHFT+PGDN. That will cycle you through all your errors.
  4. Press ALT+ENTER and choose Create Property and use the Auto-Property choice in Results, then hit ALT+SHFT+PGDN to get back to 'Calc'
Brett Veenstra
thanks, this is alleviating my RSI a little bit :)
Piers Myers