Prevent Visual Studio from adding NotImplementedException when generating method
Is it possible to configure Visual Studio to not add the
throw new NotImplementedException();
line when generating methods via quick actions?
I just want it to create an empty method.8 Replies
See this to get an idea of how to modify the templates VS uses. My experience has found that it is far more work keeping up with your mods or customs across every version update than it is to just find fast kb shortcuts to remove them. But then I really don't know your use case.
https://learn.microsoft.com/en-us/visualstudio/ide/how-to-update-existing-templates?view=vs-2022
Update existing project item templates - Visual Studio (Windows)
Use the Export Template Wizard and other manual processes in Visual Studio to update project item templates that you already created.
but why? its very helpful to generate the
throw new NotImplementedException()
because until you've implemented thats exactly what it should do, to point out that it's missing an implementation. If you have empty methods in your code and accidentally forget to edit them then you could run into unexpected behavioursThere's a setting for this in VS
Ah sorry I misread, the setting is only for properties.
I agree but 99% of the time I implement the method immediately and it's kind of annoying to delete it every time.
Yeah I was afraid that is the only way, just wish there was an option to include the exception or not
In most cases I just select one line with that statement in it, and use the SC Shift + Alt + semi-colon and delete the selected. If I remember you can just hit Ctrl + L to remove the line.
Same annoyance as new default templates sometimes there ok, but then your on project where a custom template would be nice.
Like class files...
Ctrl + L might be something IDE specific that I dont know, but what works across all IDEs to do this is Shift + Delete, that will delete the line your cursor is in
I mean I'm nitpicking here, but having to press
Shift + Del
, Up Arrow
, Enter
over and over again whereas if there was an option to omit it, I would just have to navigate to the line in the method