you can get the type of a predefined class with:
typeof(My.Library.Class).FullName
If you need a "class declaring this method", you will need to use
MethodBase.GetCurrentMethod().DeclaringType.FullName
However, there is a chance that this method will be built in by the compiler . You can switch this call to the static constructor / initializer of the class (which will never be inlined - log4net recommends this approach):
namespace My.Library public static class Class { static string className = MethodBase.GetCurrentMethod().DeclaringType.FullName; public static string GetName() { return className; } } }
Using [MethodImpl(MethodImplOptions.NoInlining)] may help, but you really should read if you are considering it
HTH - Rob
source share