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"
.
More Related Contents:
- Reflection: How to Invoke Method with parameters
- Read the value of an attribute of a method
- How to check whether an object has certain method/property?
- Reflection MethodInfo.Invoke() catch exceptions from inside the method
- what are the methods “public override bool equals(object obj)” and “public override int gethashcode()” doing? [closed]
- Getting attributes of Enum’s value
- How can I evaluate a C# expression dynamically?
- How to dynamically create generic C# object using reflection? [duplicate]
- Setting a property by reflection with a string value
- Dynamically Add C# Properties at Runtime
- How to determine if a type implements a specific generic interface type
- Get properties and values from unknown object
- Purpose of Activator.CreateInstance with example?
- How to correctly cast a class to an abstract class when using type generics?
- Creating instance of type without default constructor in C# using reflection
- C# Reflection – Get field values from a simple class
- Using Case/Switch and GetType to determine the object [duplicate]
- How do you get a variable’s name as it was physically typed in its declaration? [duplicate]
- C# reflection – load assembly and invoke a method if it exists
- Changing read only properties with reflection
- How do I check if a given value is a generic list?
- Method Within A Method
- C# Getting value of params using reflection
- Add property to anonymous type after creation
- How can I protect my private funcs against reflection executing?
- How can I get the values of the parameters of a calling method?
- How to set value of property where there is no setter
- using type returned by Type.GetType() in c#
- Reflecting a private field from a base class
- Two Types not equal that should be