c# - 从现有类生成接口(interface)

标签 c# visual-studio

我有一个类:

Class MyClass
{
   public MyClass { ... }
   public string Name { get { ... } }
   public int IdNumber { get { ... } set { ... } }
   public void GenerateNme {...}
}

这只是一个示例类。我希望从中生成接口(interface)。比如,MyClass 正在实现 IMyClass 接口(interface)。我希望输出是

public Interface IMyClass
{
   string Name { get; }

   int IdNumber { get; set; }

   void GenerateNumber();
}

MyClass : IMyClass
{

}

它可以手动完成,但我只是想知道,是否有其他简单的方法可以完成此操作?如果不清楚,请发表评论。

谢谢。

最佳答案

是的,您可以使用 Visual Studio 从类中提取接口(interface):

在目标类文件中:右键单击> Refactor> Extract Interface...

示例

enter image description here

然后

enter image description here

关于c# - 从现有类生成接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9277011/

相关文章:

c# - 以灰度显示表单

c# - 有没有办法传播多次注入(inject)?

c# - 所选文本未显示在 WPF 窗口中的 Windows 窗体 RichTextBox 控件中

c++ - 在调试中,如何知道函数重复调用中参数的统计信息(最大-最小值、平均值、分布...)?

c++ - 在共享项目中包含代码仅在选择 x64 平台时有效

c# - EF 拥有和反向 POCO 生成器都跳过表

c# - 为什么这条语句会抛出空引用异常呢?

c++ - 为什么我的 DLL 不需要 DllMain 函数?

visual-studio - 为什么 Visual Studio 2010 不保存环境常规设置?

c++ - 使用 Visual Studio 2008 从 x86 编译 x64 dll : unresolved external __imp_ symbols