How do I find the type of the object instance of the caller of the current function?

前端 未结 5 570
误落风尘
误落风尘 2021-02-06 07:37

Currently I have the function CreateLog() for creating a a log4net Log with name after the constructing instance\'s class. Typically used as in:

class MessageRe         


        
5条回答
  •  深忆病人
    2021-02-06 08:05

    Normally, MethodBase.ReflectedType would have your info. But, according to MSDN StackFrame.GetMethod:

    The method that is currently executing may be inherited from a base class, although it is called in a derived class. In this case, the ReflectedType property of the MethodBase object that is returned by GetMethod identifies the base class, not the derived class.

    which means you're probably out of luck.

提交回复
热议问题