Open sandboxFocus

Class StateAttribute

Binds a parameter of an advice method to a variable shared by the advices of an advice group, for instance to pass a value from OnMethodEntryAdvice to OnMethodExitAdvice.

Inheritance
StateAttribute
Namespace: PostSharp.Aspects.Advices
Assembly: PostSharp.dll
Syntax
public sealed class StateAttribute : AdviceParameterAttribute
Remarks

Each variable is a slot identified by its name, which is SlotName, or the name of the parameter when SlotName is null. The advices of one group that bind the same slot share one variable, and all their parameters must have the same type. The variable lives for one invocation of the target method, as specified by MethodInvocation, and its initial value is the default value of its type. In an async method or an iterator, the variable is a field of the state machine, so it keeps its value across await and yield statements.

A ref or out parameter can change the value of the variable. A parameter without modifier, or an in parameter, receives the current value.

Constructors

Name Description
StateAttribute(StateScope)

Initializes a new instance of the StateAttribute class with a slot named after the parameter.

StateAttribute(StateScope, string)

Initializes a new instance of the StateAttribute class with a slot of a given name.

Properties

Name Description
Scope

Gets the lifetime of the variable.

SlotName

Gets the name of the slot, or null when the slot is named after the parameter.

See Also