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++) 
{ 
try
{
Type  myType=Type.GetType(oStack.GetFrame(i).GetMetho).ReflectedType.FullName);
String str = myType.ToString();
if(myType.IsClass)
Console.Write(oStack.GetFrame(i).GetMethod().ReflectedType.FullName  + "\n");   
}
catch
{
}
}
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.
Sravan.

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

http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=330

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

http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=330