gpt4 book ai didi

c# - Visual Studio 2010 是否支持 Eclipse 的 "Generate delegate methods"之类的东西?

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

Eclipse 允许我们定义一个类:

interface MyInterface {
void methodA();
int methodB();
}

class A : MyInterface {
MyInterface myInterface;
}

然后使用这个“生成委托(delegate)方法”,它将为接口(interface)实现所有需要的方法,将它们的逻辑重定向到 myInterface 的方法:

class A : MyInterface {
MyInterface myInterface;

public void methodA() {
myInterface.methodA();
}

public int methodB() {
return myInterface.methodB();
}
}

是否有可能用 VS2010 完成同样的事情?还有 R#?

谢谢

最佳答案

借助 Resharper,您可以做到这一点。

http://www.jetbrains.com/resharper/features/code_generation.html

Generate Delegating Members

Delegating members provides a means to encapsulate some behavior or publish methods of a class's field through the class's own interface. Specify fields and their methods, and ReSharper will generate wrapping methods in the current class.

这是我们一直使用的一个很棒的功能。有几种方法可以访问它,但我所做的是点击 ALT-INS,这会弹出 Generate 上下文菜单。列表中的几项是Delegating members。然后你会得到一棵树,你可以从中选择你想要委托(delegate)的字段(对象)以及你想要创建的委托(delegate)属性/方法。非常快速和简单,效果很好。

关于c# - Visual Studio 2010 是否支持 Eclipse 的 "Generate delegate methods"之类的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2679239/

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