PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.AutoResetter< T > Class Template Reference

Provides a mechanism to run code on construction and disposal, irrespective of exception handling Use this, for example, to set up and tear down state required for a test – your constructionAction is called immediately upon construction and the using() pattern guarantees that your disposalAction is called at disposal, even if your test fails. More...

Inheritance diagram for PeanutButter.Utils.AutoResetter< T >:

Public Member Functions

 AutoResetter (Action constructionAction, Action disposalAction)
 Constructs a new AutoResetter and immediately runs the constructionAction.
 
 AutoResetter (Action disposalAction)
 Constructs a new AutoResetter with the disposal action set and no construction action.
 
void Dispose ()
 
 AutoResetter (Func< T > start, Action< T > end)
 Constructs a new AutoResetter, runs the start Func and stores the result.
 
void Dispose ()
 

Static Public Member Functions

static AutoResetter Create (Action onStart, Action onDisposed)
 Convenience to create an AutoResetter without new or having to care about whether you're using the action or func variant.
 
static AutoResetter< T > Create< T > (Func< T > onStart, Action< T > onDisposed)
 Convenience to create an AutoResetter without new or having to care about whether you're using the action or func variant.
 

Detailed Description

Provides a mechanism to run code on construction and disposal, irrespective of exception handling Use this, for example, to set up and tear down state required for a test – your constructionAction is called immediately upon construction and the using() pattern guarantees that your disposalAction is called at disposal, even if your test fails.

Provides a mechanism to run code on construction and disposal, irrespective of exception handling Use this, for example, to set up and tear down state required for a test – your constructionAction is called immediately upon construction and the using() pattern guarantees that your disposalAction is called at disposal, even if your test fails. This is the variant of AutoResetter where:

  1. The start Func returns a value
  2. Upon disposal, the end action is called with the value from (1)
Template Parameters
TType of value which is passed to the start and end actions

Constructor & Destructor Documentation

◆ AutoResetter() [1/3]

PeanutButter.Utils.AutoResetter< T >.AutoResetter ( Action  constructionAction,
Action  disposalAction 
)

Constructs a new AutoResetter and immediately runs the constructionAction.

Parameters
constructionActionAction to run at construction time
disposalActionAction to run at disposal time

◆ AutoResetter() [2/3]

PeanutButter.Utils.AutoResetter< T >.AutoResetter ( Action  disposalAction)

Constructs a new AutoResetter with the disposal action set and no construction action.

Parameters
disposalAction

◆ AutoResetter() [3/3]

PeanutButter.Utils.AutoResetter< T >.AutoResetter ( Func< T >  start,
Action< T >  end 
)

Constructs a new AutoResetter, runs the start Func and stores the result.

Parameters
startCode to run at construction
endCode to run at disposal; will receive the result provided from the start Func

Member Function Documentation

◆ Create()

static AutoResetter PeanutButter.Utils.AutoResetter< T >.Create ( Action  onStart,
Action  onDisposed 
)
static

Convenience to create an AutoResetter without new or having to care about whether you're using the action or func variant.

Parameters
onStart
onDisposed
Returns

◆ Create< T >()

static AutoResetter< T > PeanutButter.Utils.AutoResetter< T >.Create< T > ( Func< T >  onStart,
Action< T >  onDisposed 
)
static

Convenience to create an AutoResetter without new or having to care about whether you're using the action or func variant.

Parameters
onStart
onDisposed
Returns

The documentation for this class was generated from the following files: