Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. public static long Measure(Action action)
  2. {
  3. Stopwatch sw = new Stopwatch();
  4. sw.Start();
  5. action();
  6. return sw.ElapsedMilliseconds;
  7. }
  8.  
  9. var duration = Measure(() => MyMethod(param1));
  10.  
  11. TimerInterceptor : IInterceptor
  12. {
  13. public void Intercept(IInvocation invocation)
  14. {
  15. Stopwatch watch = new Stopwatch();
  16. watch.Start();
  17. invocation.Proceed();
  18. watch.Stop();
  19. //here you have the value which could be used to log (which I assume you want)
  20. }
  21. }
  22.  
  23. new ProxyGenerator().CreateInterfaceProxyWithTarget<IMyInterface>(implementedObject, new TimerInterceptor());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement