In .NET 4.5 / C# 5, this is simple:
public void PopularMethod([CallerMemberName] string caller = null)
{
// look at caller
}
The compiler adds the caller's name automatically; so:
void Foo() {
PopularMethod();
}
will pass in "Foo"
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…