【问题标题】:C# generate code from interface [duplicate]C#从接口生成代码[重复]
【发布时间】:2014-04-07 10:05:57
【问题描述】:

我在C#. 中有一个interface 定义是否有任何工具可以自动创建(生成)具有默认返回类型的该接口的所有空方法? 例如我已经有:

interface ISampleInterface
{
    void SampleMethod();
    int func(int);
}

我想要:

// auto interface member implementation:
class ImplementationClass : ISampleInterface
{

    void ISampleInterface.SampleMethod()
    {

        return;
    }

    // changed return type to int according to interface definintion
    int ISampleInterface.func(int a)
    {

        return a;
    }

}

【问题讨论】:

  • 考虑使用“Re-sharper”工具。
  • VisualStudio 在没有 Resharper 的情况下也是如此。
  • @PranavSingh 仅限 Visual Studio 的某些版本
  • @verdesrobert 哦,我不知道我用过高级、专业和终极版都有。可能快递没有。
  • @PranavSingh 确切地说:D 一些 Express 版本的功能非常少

标签: c# interface code-generation


【解决方案1】:

只需右键单击您的class ImplementationClass : ISampleInterface,然后单击Implement Interface

否则你可以考虑使用Re-sharper 工具

【讨论】:

  • 仅适用于特定版本的 Visual Studio
  • @verdesrobert:- 更新了我的答案!
  • @user3414693 谢谢!
  • @zeus2:- 不客气!
【解决方案2】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 2015-10-25
    • 2017-05-11
    • 1970-01-01
    相关资源
    最近更新 更多