Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio - automatically implement all inherited methods from an interface

Let's say we have a class called MyClass.

public class MyClass

We also have an interface like so:

public interface MyInterface{

public string SomeFunction(int foo, string bar, short baz){}
}

We want this class to inherit from MyInterface.

public class MyClass: MyInterface

MyInterface has n properties, and i methods. How can I get Visual Studio to automatically implement all those methods and properties without the developer doing any of the legwork?

like image 342
p.campbell Avatar asked May 19 '09 17:05

p.campbell


3 Answers

For C#, you can right click the 'MyInterface' and choose 'Implement Interface' from the context menu. I believe there is a similar (but slightly different) shortcut for VB.NET.

like image 101
Harper Shelby Avatar answered Nov 07 '22 13:11

Harper Shelby


You can simply use shortcut "CTR+." to do that. Position your cursor on MyInterface of "public class MyClass: MyInterface" line, and press "CTR+.", a context menu will show up with "Implement Interface ...".

like image 20
Qinjie Avatar answered Nov 07 '22 13:11

Qinjie


To automatically implement all inherited methods from an interface:

C# : Just right click on interface(Prefix with 'I') name and select implement interface option.

VB.NET : Just point your cursor after interface(Prefix with 'I') name and hit enter.

Enjoy!!!

like image 3
Ejaz Waquif Avatar answered Nov 07 '22 12:11

Ejaz Waquif