4

如何表达仅在从另一个方法中调用而不是直接调用时才找到方法的切入点?

例如:

Foo() calls Bar() calls object.Method()

NotFoo() calls Bar() calls object.Method()

我只希望切入点在 Foo() 中工作

我尝试了“代码内”,但这似乎只能直接工作。

谢谢埃里克

4

1 回答 1

4

What you want actually requires two joinpoints:

  1. call method or constructor in Bar class and be within Foo class or eventually Foo() constructor with withincode designator. The advice to this joinpoint can for example set a flag that to true when called from Foo() and falso otherwise. This variabel can be stored in a HashMap with the thread as key to avoid concurrency issues.
  2. withincode Bar() constructor or within Bar class and call object.Method(). The advice to this joinpoint must also check if the flag is set to true. And finally set the Foo flag to false again.
于 2010-10-05T10:33:08.187 回答