Click here to Skip to main content
15,742,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
MethodA(Delegate obj)
{
  MethodB(obj):
}

MethodB(Delegate obj)
{
  MethodC(obj):
}


MethodC(Delegate obj)
{
  //By using obj need to Track all The Travellled Methods info

  // Like MethodA.MethodB.MethodC
}
Posted
Comments
Tomas Takac 26-Nov-14 4:16am    
The delegate is just and parameter to your methods, so it's not important in this context. Is System.Diagnostics.StackTrace[^] what you are looking for?

1 solution

Parameter arguments to a Method are private variables existing only in the scope of the Method ... unless you use 'ref or 'out ... but I don't think there's any practical way at run-time, even using 'out/'ref, to find out where a given object has "visited" as it may be passed from method to method.

The closest thing I can think of to what you may be after is using reflection at run-time on a multi-cast Event delegate ... where you do not have references to the delegates in its invocation list ... to get its invocation list and enumerate its delegates. Here's an example of doing that: [^].

Assuming you wanted to use non-static elements in a Class, you could do something like this:
C#
public class History
{
    public static List<string> MethodHistory = new List<string>();

    public static void Report()
    {
        foreach (var str in MethodHistory) Console.WriteLine(str);
    }
}

private void act0()
{
    History history = new History();
    History.MethodHistory.Add("act0");
    act1(ref history);
}

private void act1(ref History history)
{
    History.MethodHistory.Add("act1");
    act2(ref history);
}

private void act2(ref History history)
{
    History.MethodHistory.Add("act2");
    act3(ref history);
}

private void act3(ref History history)
{
    History.MethodHistory.Add("act3");
    History.Report();
}
</string></string>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900