✅ Get instance name inside of class
So i have class like this:
and i want to create
ToString
that will return -[nameOfTheCliFlag] [valueOfTheFlag]
like this
however i can't find o way to get the name of the current instance inside of the class, i thought about nameof(this)
, but that doesn't work
is there any way how to get this working without passing the name of the flag from outside?5 Replies
That's not even the name of the current instance. That's the name of the variable to which the current instance is assigned
fair
And no, there's no way to find that. Your instance might not even be assigned to a variable: it might be stored in a list, or simply be an expression.
Also variable names are lost at compile time
ok, i guess that makes sense, thanks for help, i will try different approach here
store the name alongside the value