0

Before posting this question I spent almost 3 hours looking for the similar questions. the closest that I found was asking how to Prevent this. but I'm looking for a way to do it automatically.I have an interface which has been implemented in multiple classes. when I'm adding a another property to that interface I have to go and update all the references. I was wondering if there's anyway to auto-implement that field in all the classes/interfaces that have implemented that interface? similar to when you refactor a method name and all of its references will be updated with the new name! let's say I add MyProperty to an interface, the following is expected to be auto-generated in all its references.

public string MyProperty {get; set;}

Thank you

Community
  • 1
  • 1
John New
  • 1
  • 1
  • What is the expected implementation? All I can think of is `throw new NotImplementedException();`, but that just moves the error from compile-time to runtime--usually you try for the opposite. – 31eee384 Aug 19 '15 at 03:55
  • @31eee384 thorw new NotImplementedException() is for methods. I'm looking for the properties. my expected implementation is similar to C# Auto-Implemented Properties. Thank you – John New Aug 19 '15 at 04:10
  • It's good to know that you want auto-properties to be generated, but it's not true that `NotImplementedException` is for methods. By default Visual Studio fills in a non-implemented property with `public int MyProperty { get { throw new NotImpl...(); } set { throw new NotImpl...(); } }` (I do this by putting the cursor over the red-squigglied interface, pressing control+., and selecting "Implement interface".) Do you have Resharper? – 31eee384 Aug 19 '15 at 04:17
  • @31eee384 Yeah, doing it manually, I have to go to every single reference and right click on the Interface name and click onImplement interface. and it will add the missing properties with NotImplementedException. however there's a way that you can change it so instead of NotImplementedException , it will put get; set; which is explained [Here](http://stackoverflow.com/questions/17703277/how-can-i-make-implementation-of-an-interface-produce-an-auto-property-instead-o#) and no I don't have ReSharper. – John New Aug 19 '15 at 04:53
  • Ok, sorry I couldn't be any help. Maybe you should add that extra info to your question, though: that you want to implement the properties as `get; set`. (Backticks/grave accents (\`) for code formatting, by the way.) – 31eee384 Aug 19 '15 at 04:56
  • @31eee384 `thank you` – John New Aug 19 '15 at 05:06

0 Answers0