How can I make implementation of an interface produce an auto property instead of NotImplementedException?
c#, visual-studio, visual-studio-2010
Solution
You need to change the template used by Visual Studio when you click on `Implement Interface`. The template is stored in the following location:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Refactoring
The template you need to change is called `PropertyStub.snippet`
NOTE: I would back up the existing snippet file before making changes so that you can easily revert if things do not go well.
The lines you need to update are:
$GetterAccessibility$ get
{
$end$throw new $Exception$();
}
$SetterAccessibility$ set
{
throw new $Exception$();
}
The lines should be changed to this:
$GetterAccessibility$ get;
$SetterAccessibility$ set;
Problem
Consider that we have a simple interface such as `ICar` when I move mouse over ICar expression and click on `Implement Interface` Visual Studio generates below implementation. Is there any way of having just an auto property as seen in below sample. I believe this will improve implementation time, since most of the time auto property is the intended implementation. ``` public interface ICar { double Power { get; set; } } public class Car:ICar { public double Power { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } } ```