Take a look at C# get the name of a method that called another one [duplicate]. It was closed with 4 suggested links. The youngest of those is 8 years old. The obvious answers (accepted or highly voted) all point out that the way to do what the OP is asking is to walk up the stack using the facilities in System.Diagnostics.
In the second of those suggested links, the accepted answer (429 votes) includes this note at the end:
UPDATE Two years later since I'm still getting upvotes on this
In .Net 4.5 there is now a much easier way to do this. You can take advantage of the
CallerMemberNameAttribute
In a couple of the other questions, there are later answers that point out that CallerMemberNameAttribute
is the way to go. But they generally are getting single digit votes - the kind of answers that tend to be ignored.
The question I'm referring to is closed. I added comments pointing out the modern way to do this. How should this be handled?
Update (after reading the comments and the answer)
Perhaps the solution is to add a box (similar to the closed box) that says something like:
A Newer Answer May Suit Your Needs Better
Since this question was asked and answered, the underlying technology has been changed/advanced. Consider these answers as well as those posted below.
In the case of the example I show above, the original answers may be appropriate for some users. For most, I suspect the more modern approach is a better solution. This would need to be presented as an either/or, not as a "deprecated" thing.
Of course, the problem is "how to manage this". Perhaps with rules similar to close voting. I'm not sure.
foreach(question trying to do what the OP is trying to do in duplicate linked list) { comment("Don't use the inefficient method, you can do X instead")}
, but the giant signposts in SO itself will lead readers down the wrong path, sadly. Also, I'm pretty sure the duped questions aren't just outdated, I'm pretty sure the solution was never optimal for Q[0] and Q[1] in the dupe chain, I'm pretty sure tuples had indexed access from day 1.