Resharper convert auto-property to full property

2020-08-09 05:50发布

问题:

I found the opposite here, but I need to frequently change from auto-property to full property - would it be possible to automate that (and with a shortcut perhaps):

From Auto-Property

public string FirstName { get; set; }

To Property with Backing Field

    private string _firstName;

    public string FirstName
    {
        get
        {
            return _firstName;
        }
        set
        {
            _firstName = value;
        }
    }

Obviously, I would then change the full property further ...

回答1:

Place your cursor on the property name, then wait a second or two. Press the Resharper hotkey sequence (Alt-Enter) and the second option should be "To property with backing field" which is what you want.

Alternatively, you can click the "hammer" icon in the left margin to get the option.



回答2:

To make it work (ALT-Enter) you must to configure resharper keyboard schema. VS -> Tools -> Options -> ReSharper -> General -> Options -> Keyboard and menus -> Resharper keyboard Schema -> Visual Studio