3

Is it possible to intercept class constructor and destructor calls using PostSharp? I would like to create active instances counter for classes.

Tomas
  • 17,551
  • 43
  • 152
  • 257

1 Answers1

2

You can use OnMethodBoundaryAspect on constructor and destructors. Note that classes don't have destructors by default in C# and VB, and destructors are called at a non-deterministic moment.

Remember that constructors can be called in chain, and the aspect is going to be applied on every constructor in the chain.

Gael Fraiteur
  • 6,759
  • 2
  • 24
  • 31