Determine calling method from within called method?

dotnet framework

    Next

  • 1. Profiler
    Can anyone recommend a good profiler for .NET? It should support both vb.net and c#. Thanks
  • 2. MFC App compiled with /clr
    Hello, We successfully compiled (on .NET 2003) and ran a MFC application using COM, and then we try to compile it with /clr switch on .NET 2003. The compilation is successful, but the MFC app failed to start with an error thrown "Cannot change thread mode after it is set..", when calling HRESULT hr(::CoInitialize(NULL));. Could someone please help? Thanks in advance, Kaixin
  • 3. Old version of CLR
    Can I un-install V1.0 of the framework leaving V1.1 installed without any ill effects? Thanks -- Ken Galer Preferred Utilities Corp. XXXX@XXXXX.COM

Determine calling method from within called method?

Postby Ben Fidge » Sat, 24 Jul 2004 23:24:46 GMT

From within a method of a class, how do you determine the 
name of the class.method that called it, programmatically?

I have a log file class, and it would be very beneficial 
to be able store the name of the class and method that 
called my LogFile.Write method.

Kind regards

Ben


Re: Determine calling method from within called method?

Postby Christopher Wells » Sun, 25 Jul 2004 00:33:58 GMT






Perhaps the System.Diagnostics.StackTrace class is what you want.



RE: Determine calling method from within called method?

Postby U3JpZGhhcg » Sun, 25 Jul 2004 06:00:03 GMT

Hi,

  May be You can use 

      System.Reflection.MethodBase.GetCurrentMethod().DeclaringType which will give the class name from which it is called. 

Sridhar!!






RE: Determine calling method from within called method?

Postby ataleb » Wed, 28 Jul 2004 01:01:50 GMT

You can use System.Diagnostics.StackTrace to get the calling method using 
GetFrame method.


Similar Threads:

1.Calling non-static methods from within static methods.

Is the following legal/recommended? (It compiles w/o error or
warnings)

class MyClass()
{
    public MyClass()
    {
    }

    private string NonStaticMethod()
    {
        retrun "Something";
    }

   private static string StaticMethod()
   {
      MyClass mc = new MyClass();

      return mc.NonStaticMethod();
    }
}

2.Calling an attribute method before calling a method with that attribute

Hallo,

I need to make an Attribute, which checks the minimal authorization 
(authorization is specific for application) for calling class method. It 
can looks like this:

[Authorization(Rights.Read)]
void SomeMethodRequiresTheReadAccess()
{.....}

But in this case no method of AuthorizationAttribute is called. I add 
only attribute to method's collection of attributes and I must tested 
the authorization inside the method (respects the attribute value).

Does anybody help me?

		George

3.static method call vs. Singleton method call - performance

I was involved recently in desiging a middle tier class where we essentially
need not track the state of the object, hence  a class with static methods
was preferred. But there were some debate as to whether it made sense to
implement it as a singleton.

 I wanted to know if there is any performance difference in CLR when calling
a static method vs. an call to instance method (where just a single instance
is used) - considering that there might be an initial expense in creating
the object on the heap.

Thanks
Victor


4.Reflection: Determining a Method's Attributes from within the Method

Is it possible to determine a method's own attributes from within the method
without hardcoding the name of the method as a constant within the method?
Please tell me if it is possible and how it is done.

Thank you,
Kelly




Return to dotnet framework

 

Who is online

Users browsing this forum: No registered users and 61 guest