Monday, August 17, 2009

c# using reflection to get current class name

If you are inside the class method, and don’t have access to an instance of the object, use:

MethodBase.GetCurrentMethod().DeclaringType.FullName;

If you hava access to an instance of the object, then:

public static class SomeClass
{
public static string FullName
  {
    get { return typeof(SomeClass).FullName; }
  }
}

No comments: