in my application i have a little action log. In there I save the last few calls of certain methods in my application like this:
saveLastAction(MethodBase.GetCurrentMethod(), getCurrentStatus(), item, /*loadFresh*/ false);
It allows me to navigate and refresh through my last actions
public void Refresh(bool loadFresh = true)
{
if (!isInitialized) return;
try
{
lastStatus = getCurrentStatus();
var parameters = lastActionsParameters.Pop();
var method = lastActions.Pop();
//Set the load Fresh parameter to True
parameters[method.GetParameters().First(pi => pi.Name == "loadFresh").Position] = loadFresh;
//Invoke the Method again with the adopted parameters
method.Invoke(this, parameters);
}
catch
{
}
}
I worked perfectly until i changed one of the methods which calls saveLastAction to async. Since then MethodBase.GetCurrentMethod()
only returns the MoveNext function and not the actual function i called.
Is there a way to get to the actual MethodBase Object of the called function, whether at the time of saving or calling doesn't matter.
Best regards lolsharp
This is going to a get a whole lot easier in C#7 using local functions:
You can already achieve this with anonymous methods or delegates but this makes the code it very clearn.