Solved

in C# dll, how to know the calling method's name?

Posted on 2004-09-13
2
1,034 Views
Last Modified: 2008-03-06
I know how to get the calling app's name from the body of the C# dll, but how do i find out that which mehtod of the client app is calling the method of the DLL?

The dll is a common class libary created in C#. Calling app is also created in C#

Thanks!
0
Comment
Question by:cliffairal
  • 2
2 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12047867
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 250 total points
ID: 12047912
using System;
using System.Diagnostics;
namespace ConsoleApplication28
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class1
      {

            private static void TestMethod(int i) {
                  StackFrame sf = new StackFrame(1);
                  StackTrace st = new StackTrace(sf);
                  for(int j=0;j<st.FrameCount;j++) {
                        Console.WriteLine("Method name - " + st.GetFrame(j).GetMethod().Name);
                        Console.WriteLine(st.GetFrame(j).GetMethod().ToString());
                  }      
            }

            [STAThread]
            static void Main(string[] args)
            {
                  try {
                        TestMethod(0);
                  }
                  catch (Exception Ex) {
                        Console.WriteLine(Ex.ToString());
                  }
            }
      }
}
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question