Hi folks,
i'm wondering if it is possible to programattically recurse up a stack trace to a particular assembly.
I'm using StructureMap
and it creates an instance of a particular class, to inject into another class. kewl. When i'm in the constructor of the injected class, i wish to see what was the parent class and the stack trace more or less has a score of structuremap methods which are called.
So, i wish to find the method which called this structuremap injection, by recursing up the stack trace GetCurrentMethod()
methods until we don't have a structuremap class.
something like...
var callingMethod = System.Reflection.MethodBase.GetCurrentMethod();
while (callingMethod.DeclaringType.ToString().Contains("structuremap"))
{
// get parent calling method, from the variable 'callingMethod'.
}
// here means we've recursed high enough or we have no more to go (null??).
can someone help?
Update
This question is closely related to this SO question ... which I ended up adding my own answer, based on the answer from here :)