C# Get Name of Derived Type from Inside base Class

前端 未结 4 1916
死守一世寂寞
死守一世寂寞 2021-02-05 02:39

During a debug session, it\'s important for me to identify the name of the actual derived class in the debug info of specific instances.

I tried using this

4条回答
  •  鱼传尺愫
    2021-02-05 03:15

    During a debug session...

    Remember that instead halting a session to add some throw-away code to then recompile and restart, one can use the debugger to divine that after the breakpoint is hit...

    By utilizing the Immediate Window of the debugger and typing a this.GetType().Name off of the instance in question and then pressing Enter, it will be shown.

    See VS Docs: Immediate Window

    Is there a simple way to get the type of the derived class from within the base class?

    Yes, for an example I can determine what the exception is by using the Name property of GetType and in real time:

提交回复
热议问题