// Collection of code snippets by Arne Vajhøj // posted to eksperten.dk, usenet and other places (2002-now) using System; using System.Collections.Generic; using System.Threading; using DotNetGuru.AspectDNG.Joinpoints; public class MethodTracker { private static Dictionary> methods = new Dictionary>(); public static string GetCurrentMethod() { return methods[Thread.CurrentThread.ManagedThreadId].Peek(); } [AroundCall("* E.TestAop::*(*)")] public static object SaveMethod(JoinPoint jp) { if(jp is MethodJoinPoint) { if(!methods.ContainsKey(Thread.CurrentThread.ManagedThreadId)) { methods.Add(Thread.CurrentThread.ManagedThreadId, new Stack()); } MethodJoinPoint mjp = (MethodJoinPoint)jp; methods[Thread.CurrentThread.ManagedThreadId].Push(mjp.TargetOperation.DeclaringType.FullName + "." + mjp.TargetOperation.Name); } object res = jp.Proceed(); if(jp is MethodJoinPoint) { methods[Thread.CurrentThread.ManagedThreadId].Pop(); } return res; } }