Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-generate an interface implementation in C#?

Tags:

I know this is quite lazy but, is there any way on Visual C# 2010 Express to auto-generate an interface implementation? (I don't mean at runtime but at design time, like a code snippet). Perhaps with a third party utility?

like image 941
Juan Avatar asked Aug 10 '10 17:08

Juan


People also ask

How do you automatically implement an interface in C#?

All you need to do is hover over the interface name in the class, and the blue underline bar should show up, giving you options to implement the interface. If the blue underline is not appearing, check to make sure the interface is accessible with what assemblies and namespaces you are referencing.

How do you implement an interface?

To declare a class that implements an interface, you include an implements clause in the class declaration. Your class can implement more than one interface, so the implements keyword is followed by a comma-separated list of the interfaces implemented by the class.

Can I create an interface from class?

Yes, you can define an interface inside a class and it is known as a nested interface. You can't access a nested interface directly; you need to access (implement) the nested interface using the inner class or by using the name of the class holding this nested interface.


2 Answers

I'm not familiar with Express enough to know if they removed this feature, but you should just be able to right-click your public class MyClass : MyInterface statement and choose "Implement Inteface".

If this is removed in Express, you can always use Resharper for this feature.

like image 183
womp Avatar answered Sep 22 '22 15:09

womp


Right click on the interface name, you should see a menu option "Implement Interface" or along those lines.

With the cursor on the interface name, you can also press CTRL + . to get the same context menu and options.

like image 25
Babak Naffas Avatar answered Sep 24 '22 15:09

Babak Naffas