简体   繁体   English

Visual Studio 2010是否支持Eclipse的“生成委托方法”?

[英]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.

相关问题 使Visual Studio 2010看起来像Eclipse? - Making Visual Studio 2010 Look Like Eclipse? Visual Studio 2010对.NET 4.5的支持 - Visual Studio 2010's support for .NET 4.5 Eclipse像Visual Studio 2010 C#中的控制台 - Eclipse like console in Visual Studio 2010 C# Visual Studio Express 2015是否支持TFS 2010? - does visual studio express 2015 support TFS 2010? 所请求的资源在Visual Studio 2010中不支持HTTP方法“ GET” - The requested resource does not support HTTP method 'GET' in visual studio 2010 视觉工作室2010中的json支持 - json support in visual studio 2010 为什么Visual Studio 2010告诉我“'System.Delegate'不包含'EndInvoke'的定义”? - Why is Visual Studio 2010 telling me “'System.Delegate' does not contain a definition for 'EndInvoke'”? 我可以在Visual Studio 2010中自动为按钮,复选框等生成方法吗? - Can I automatically generate methods for Buttons, Checkboxes, etc. in Visual Studio 2010? 类似于Visual Studio 2010的Windows窗体应用程序的多监视器支持? - Visual Studio 2010-like multiple-monitor support for Windows Forms applications? 是否有Visual Studio 2010扩展来对方法进行排序? - Is there a Visual Studio 2010 extension to sort methods?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM