Get the instance name of this

后端 未结 4 1737
攒了一身酷
攒了一身酷 2021-01-22 08:50

Is this possible!!?!?!?!?

I\'m trying to make a set of classes that model a number of different types of things. Properties of these things change over time, and I want

4条回答
  •  春和景丽
    2021-01-22 09:48

    Given the question as is, It is would be very hard, if not impossible, to do so.

    With debugging symbols, it is possible to dig up through stack frames and enumerate the local variables and match the address with the instance address. However, the approach won't work because the constructor will be invoked before the reference got set, so the tiger will be null at the time and matching will fail all the time.

    Yet if I can alter the question, the solution might be that you need to call MAGICSTUFF.GetInstanceName(this); in getter method of CatName instead, so my approach should be working fine.

    Now I'm trying to writing some code to do so, though I would post it here if someone might read this and come up with the real implementation before me.

提交回复
热议问题