[英]Does Visual Studio 2010 support something like Eclipse's “Generate delegate methods”?
Eclipse allows us to define a class as: Eclipse允许我们将类定义为:
interface MyInterface {
void methodA();
int methodB();
}
class A : MyInterface {
MyInterface myInterface;
}
and then with this "Generate delegate methods", it will implement all needed methods for the interface, redirecting their logic to myInterface's methods: 然后使用这个“生成委托方法”,它将实现接口所需的所有方法,将其逻辑重定向到myInterface的方法:
class A : MyInterface {
MyInterface myInterface;
public void methodA() {
myInterface.methodA();
}
public int methodB() {
return myInterface.methodB();
}
}
Is it possible to accomplish the same with VS2010? 是否有可能用VS2010完成相同的操作? And with R#? 和R#?
Thanks 谢谢
With Resharper you can do this. 使用Resharper,你可以做到这一点。
http://www.jetbrains.com/resharper/features/code_generation.html 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. 指定字段及其方法,ReSharper将在当前类中生成包装方法。
This is a great feature that we use all the time. 这是我们一直使用的一个很棒的功能。 There are a few ways to access it but what I do is hit ALT-INS
which brings up the Generate
context menu. 有几种方法可以访问它,但我所做的是点击ALT-INS
,它会调出Generate
上下文菜单。 A few items down on the list is Delegating members
. 列表中的一些项目是Delegating members
。 Then you get a tree from which you select the fields (objects) you want to delegate to and which delegating properties/methods you want to create. 然后,您将获得一个树,您可以从中选择要委派的字段(对象)以及要创建的委派属性/方法。 Very quick and easy and works great. 非常快速和简单,工作得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.