C# Get Name of Derived Type from Inside base Class

前端 未结 4 1921
死守一世寂寞
死守一世寂寞 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:05

    this.GetType().Name always return the name of the current executing type, not the type that the code that it was written in. You can emulate breakpoints though, using Debugger.Break() in a conditional manner:

    if (this.GetType().Name == "Problematic type")
        System.Diagnostics.Debugger.Break();
    

提交回复
热议问题