The first thing that comes to our mind when we think about defining a call flow is to check the call stack. But checking the stack frames can only give us the current call hierarchy, not the previous one. ie Even if you check the stack frames in C3, it will not have call history A B. This does not work.
This means that each method invoked must also somehow participate in achieving this goal. Each method must somehow determine that the caller wants to track the flow and should help provide the necessary information. But adding some code to every possible method that you can name is just ridiculous.
Another way to do this is to delegate this to someone who can intercept every method call, check if the caller wants to monitor the flow, and register the required information, which can be accessed later. It is here that I think Aspect Oriented Programming (AOP) is included in the image. To use AOP in .Net, check out PostSharp. If I get the time, I will try to come up with a sample code, but for now I can only point to this URL: http://www.postsharp.net
Hope this helps.
source share