C# .NET - how to find Calling class name in C#

Asked By Chandra Shekara Julakanti on 30-Aug-04 07:10 PM
int nStackCnt=0; 
StringBuilder oString = new StringBuilder(); 
StackTrace oStack = new StackTrace(true); 
nStackCnt = oStack.FrameCount; 
for(int i = 0;i<nStackCnt;i++) 
Type  myType=Type.GetType(oStack.GetFrame(i).GetMetho).ReflectedType.FullName);
String str = myType.ToString();
Console.Write(oStack.GetFrame(i).GetMethod().ReflectedType.FullName  + "\n");   
I have tried the above but this gives a list of classes. This list does have the Calling class that I am looking for. Can any one help me get just calling class.

I am have a namespace and multiple classes in this namespace. Calling a method in one class from a method in a another class. I want the find out the calling class in this situation.

Thank You Very much in advance.

See here: - Asked By Peter Bromberg on 30-Aug-04 08:57 PM


This should work - Asked By Robbe Morris on 30-Aug-04 11:27 PM