Get the Namespace, Class Name, and Method Name of the Currently Executing Method Via Reflection


/ Published in: C#
Save to your folder(s)

GetFrame(1) to avoid the last method being this property accessor.
Note that in a child class inherited member, the Class name will be the name of the type containing the implementation.


Copy this code and paste it in your HTML
  1. protected string Source
  2. {
  3. get
  4. {
  5. StackTrace st = new StackTrace(true);
  6. MethodBase mb = st.GetFrame(1).GetMethod();
  7. return mb.ReflectedType.Namespace + "." + mb.ReflectedType.Name + "." + mb.Name;
  8. }
  9. }
  10.  
  11. //Use like so:
  12. public void DoChildStuff()
  13. {
  14. Log(Source, "Doing Child Stuff");
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.