ReSharper 2022.1 Help

Generate Delegating Members

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

class Point { public Point(int x, int y) { X = x; Y = y; } public int X { get; } public int Y { get; } public void DoSomething() {} } class Circle { int _radius; Point _center; }
class Point { public Point(int x, int y) { X = x; Y = y; } public int X { get; } public int Y { get; } public void DoSomething() {} } class Circle { int _radius; Point _center; public int X { get { return _center.X; } } public int Y { get { return _center.Y; } } public void DoSomething() { _center.DoSomething(); } }

Generate delegating members

  1. In the editor, set 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.

  2. Press Alt+Insert or choose ReSharper | Edit | Generate Code… from the main menu. Alternatively, you can press Control+Shift+A, start typing the command name in the popup, and then choose it there.

  3. In the Generate popup, select Delegating Members.

  4. 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.

    Generating delegating members with ReSharper
  5. 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.

This feature is supported in the following languages and technologies:

Language: C#

Language: VB.NET

Language: C++

Language: HTML

Language: ASP.NET

Language: Razor

Language: JavaScript

Language: TypeScript

Language: CSS

Language: XML

Language: XAML

Language: Resx

Language: Build Scripts

Language: Protobuf

Language: JSON

Feature is available in C#

Feature is available in Visual Basic .NET

Feature is not available in C++

Feature is not available in HTML

Feature is not available in ASP.NET

Feature is not available in Razor

Feature is not available in JavaScript

Feature is not available in TypeScript

Feature is not available in CSS

Feature is not available in XML

Feature is not available in XAML

Feature is not available in Resource files

Feature is not available in build script files

Feature is not available in Protobuf

Feature is not available in JSON

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by language section.

Last modified: 08 March 2021