C# 从接口生成代码
本文关键字:代码 接口 | 更新日期: 2023-09-27 17:57:19
我在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;
}
}
只需右键单击您的class ImplementationClass : ISampleInterface
,然后单击Implement Interface
否则,您可以考虑使用重新锐化工具
以下是使用ReSharper实现所有接口的方法(标准)
https://www.jetbrains.com/resharper/webhelp50/Code_Generation__Implementing_Overriding_Methods.html