PC Review


Reply
Thread Tools Rate Thread

How can you get the current class name without using StackTrace?

 
 
Zytan
Guest
Posts: n/a
 
      28th Apr 2007
Since the call stack can be changed in release, as functions are
inlined, how can you be certain to get the current class name of any
method that cares to know? Even IF it is an inlined method?

Seems impossible to do.

Zytan

 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGFsZQ==?=
Guest
Posts: n/a
 
      29th Apr 2007
How about this.GetType()?
--
Dale Preston
MCAD C#
MCSE, MCDBA


"Zytan" wrote:

> Since the call stack can be changed in release, as functions are
> inlined, how can you be certain to get the current class name of any
> method that cares to know? Even IF it is an inlined method?
>
> Seems impossible to do.
>
> Zytan
>
>

 
Reply With Quote
 
Zytan
Guest
Posts: n/a
 
      30th Apr 2007
> How about this.GetType()?

Ok, that returns the namespace, as well, but that should be good
enough.

Thanks,

Zytan

 
Reply With Quote
 
Zytan
Guest
Posts: n/a
 
      30th Apr 2007
> How about this.GetType()?

Oh, wait, I had already tried that, and it didn't work because I need
it to work on static classes. There is no "this" for a static class.

Any more ideas?

Zytan

 
Reply With Quote
 
Zytan
Guest
Posts: n/a
 
      30th Apr 2007
> How about this.GetType()?

this.Name

Zytan

 
Reply With Quote
 
Paul McNamara
Guest
Posts: n/a
 
      28th Jan 2011
Here's an example of something I use in a static method (should work in a static class too).

public static Type[] GetKnownTypes()
{
Type thisType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
return thisType.Assembly.GetTypes().ToList<Type>().Where(t => t.IsSubclassOf(thisType)).ToArray();
}



> On Saturday, April 28, 2007 3:29 PM Zytan wrote:


> Since the call stack can be changed in release, as functions are
> inlined, how can you be certain to get the current class name of any
> method that cares to know? Even IF it is an inlined method?
>
> Seems impossible to do.
>
> Zytan



>> On Saturday, April 28, 2007 9:08 PM dale097 wrote:


>> How about this.GetType()?
>> --
>> Dale Preston
>> MCAD C#
>> MCSE, MCDBA
>>
>>
>> "Zytan" wrote:



>>> On Sunday, April 29, 2007 7:23 PM Zytan wrote:


>>> Ok, that returns the namespace, as well, but that should be good
>>> enough.
>>>
>>> Thanks,
>>>
>>> Zytan



>>>> On Sunday, April 29, 2007 7:36 PM Zytan wrote:


>>>> Oh, wait, I had already tried that, and it did not work because I need
>>>> it to work on static classes. There is no "this" for a static class.
>>>>
>>>> Any more ideas?
>>>>
>>>> Zytan



>>>>> On Sunday, April 29, 2007 8:48 PM Zytan wrote:


>>>>> this.Name
>>>>>
>>>>> Zytan



>>>>> Submitted via EggHeadCafe
>>>>> SQL Operations on a Text File with ADO.NET
>>>>> http://www.eggheadcafe.com/tutorials...th-adonet.aspx

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
StackTrace class Curious Microsoft Dot NET 1 18th Oct 2007 08:32 PM
Stacktrace class and CLR 2.0 rani.yaroshinski@gmail.com Microsoft C# .NET 3 30th Dec 2006 04:04 PM
StackTrace class performance ernesto Microsoft C# .NET 1 9th Dec 2006 09:17 PM
Identifying the current class in a class hierarchy chrisp Microsoft C# .NET 2 16th Jun 2006 09:21 PM
How to get access to current page class from other class? John Smith Microsoft ASP .NET 9 11th Mar 2005 03:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:29 AM.