Shortcut to create automatic properties using Visual Studio 2008/2010 or Resharper 5

Posted by Piers Myers on Stack Overflow See other posts from Stack Overflow or by Piers Myers
Published on 2010-06-04T14:15:15Z Indexed on 2010/06/09 13:32 UTC
Read the original article Hit count: 257

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about visual-studio