Generate Delegating Members
ReSharper | Edit | Generate Code | Delegating Members
AltInsert | Delegating Members (ReSharper_GenerateDelegating
)
With ReSharper, you can quickly generate members that delegate execution to public members (methods and properties) available through private fields and properties — in other words, publish the desired part of the interface of any private field or property in the containing type.
In the example below, this command is used to generate delegating members for the _center
field:
Before generation | After generation |
---|---|
|
|
tip
You can configure common code generation preferences on the Code Editing | Members Generation page of ReSharper options Alt+R, O.
In the editor, place the caret at the type name or within a type at the line where you want to insert delegating members. If the caret is on the type name, the generated code will be added in the beginning of the type declaration.
Press AltInsert or choose ReSharper | Edit | Generate Code… from the main menu. Alternatively, you can press CtrlShift0A, start typing the command name in the popup, and then choose it there.
In the Generate popup, select Delegating Members.
In the Generate dialog that appears, you will see a list of private properties and fields in the current type. You can expand these items to see the members of their types. Select some or all of these type members, and ReSharper will generate wrappers in the current type that delegate execution to selected type members.
Click Finish to complete the wizard.
You can also click Options to review or modify common code generation preferences on the Code Editing | Members Generation page of ReSharper options.
tip
To bind this code generation command to its own shortcut, go to Tools | Options | Environment | Keyboard and assign a shortcut for the
ReSharper_GenerateDelegating
command.
This feature is supported in the following languages and technologies:
The instructions and examples given here address the use of the feature in C#. For more information about other languages, refer to corresponding topics in the Languages and frameworks section.