gpt4 book ai didi

c# - 仅通过转发参数生成调用类私有(private)字段方法的方法?

转载 作者:行者123 更新时间:2023-11-30 15:16:04 25 4
gpt4 key购买 nike

是否可以在 Visual Studio 或 ReSharper 中生成仅将参数转发给私有(private)字段方法的方法?

class Inner
{
public void Test(String a, String b){}
}
class Outer
{
private Inner _inner;
public Outer(Inner inner)
{_inner = inner;}
/*
//I want to generate this:
public void Test(String a, String b)
{
_inner.Test(a, b);
}
*/
}

最佳答案

您正在寻找的 Resharper 功能称为“生成委派成员”,描述为 here :

To generate delegating members

  1. In the editor, set the caret on 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 Ctrl+Shift+A, start typing the command name in the pop-up, and then choose it there.

  3. In the Generate pop-up menu, 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.
  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.

关于c# - 仅通过转发参数生成调用类私有(private)字段方法的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50563532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com