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

  • Thread starter Thread starter Zytan
  • Start date Start date
Z

Zytan

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
 
How about this.GetType()?

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

Thanks,

Zytan
 
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
 
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();
}
 
Back
Top