Sandy Sandy - 1 year ago 138
C# Question

Generate Interface from existing class

I have a class as:

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

It is just a sample class. I wish to generate Interface from it. Like, MyClass is implementing IMyClass interface. I wish the output to be

public Interface IMyClass
string Name { get; }

int IdNumber { get; set; }

void GenerateNumber();


MyClass : IMyClass


It can be done manually, but I was just curious to know, is there any other simple method to follow to accomplish this? If not clear, leave a comment.


Answer Source

Yes, you can extract an interface from a class using Visual Studio:

Inside the target class file: Right Click > Refactor > Extract Interface...


enter image description here


enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download