How to change “Generate Method Stub” to throw NotImplementedException in VS?

前端 未结 2 389
闹比i
闹比i 2021-01-12 09:37

How can I change default Generate Method Stub behavior in Visaul Studio to generate method with body

throw new NotImplementedException();

i

相关标签:
2条回答
  • 2021-01-12 10:09

    Taken from: http://blogs.msdn.com/ansonh/archive/2005/12/08/501763.aspx

    Visual Studio 2005 supports targeting the 1.0 version of the compact framework. In order to keep the size of the compact framework small, it does not include all of the same types that exist in the desktop framework. One of the types that is not included is NotImplementedException.

    You can change the generated code by editing the code snippet file: C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Refactoring\MethodStub.snippet and changing the Declarations section to the following:

            <Declarations>
                <Literal Editable="true">
                    <ID>signature</ID>
                    <Default>signature</Default>
                </Literal>
                <Literal>
                    <ID>Exception</ID>
                    <Function>SimpleTypeName(global::System.NotImplementedException)</Function>
                </Literal>
            </Declarations>
    
    0 讨论(0)
  • 2021-01-12 10:23

    There's another reason: FxCop catches instances of anybody throwing 'Exception' and flags it, but throwing instances of 'NotImplementedException' is acceptable.

    I actually like the default behavior, because it does have this differentiation. NotImplementedException is not a temporary exception to be thrown while you're working your way through your code. It implies "I mean it, I'm really not going to implement this thing". If you leave the codegen the way it is, it's easy for you to differentiate in the code the "I will come back to this later" bits from "I've decided not to do this" bits.

    0 讨论(0)
提交回复
热议问题