Open sandboxFocus

Method InitializeCurrentAspects

InitializeCurrentAspects()

Initializes all the aspects of the calling instance. This method must be invoked from an instance method (not a static method) of a type that has been enhanced by an aspect.

Declaration
public static void InitializeCurrentAspects()
Remarks

Calls to this method are transformed, at build time, to calls to this.InitializeAspects, a method that is typically generated by PostSharp. This is why the current method has no implementation.

The constructors of enhanced classes always initialize aspects. The only scenario where this method needs to be invoked manually is when instances are not created using a constructor, for example when they are created with the method GetUninitializedObject(Type).

The call is resolved at build time against the class that declares the calling method. If neither this class nor its base classes have an aspect that requires initialization, the call is removed and has no effect, even if aspects are applied to derived classes. In this case, define an InitializeAspects method in the class instead. Calling this method from a static method is a build error.

See Also