views:

1307

answers:

2

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?

+8  A: 

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.

Harper Shelby
In VB.NET, when you type a carriage return after "Implements MyInterface", Visual Studio automagically adds stubs for all the un-implemented members.
Patrick McDonald
Or the otherway around start writing the implementation and extract the Interface from the class.... You have it as an Refactor option in 2008 ....
salgo60
A: 

This is a job for macros in Visual Studio. Here is an example that does a similar thing for abstract classes. It should be enough to get you going.

Tim Hoolihan
Harper's answer is much better, note that it requires VS 2008. My current project is at a VS 2005 client, hence my macro solution...
Tim Hoolihan
Harper's solution works in Visual Studio 2005 also.
Patrick McDonald
Studio 2005 this works in C# only
Tim Hoolihan