using System;
namespace DTT.Utils.Workflow
{
///
/// Represents an action that is only executed once.
///
/// The argument type.
public class SingleAction
{
///
/// The action to execute.
///
private readonly Action _action;
///
/// Whether the action is invoked.
///
private bool _invoked;
///
/// Initializes the action.
///
/// The action to execute once.
public SingleAction(Action action) => _action = action;
///
/// Invokes the action if not already invoked once.
///
/// The argument for the action.
public void Invoke(T argument)
{
if (_invoked)
return;
_action.Invoke(argument);
_invoked = true;
}
}
///
/// Represents an action that is only executed once.
///
public class SingleAction
{
///
/// The action to execute.
///
private readonly Action _action;
///
/// Whether the action is invoked.
///
private bool _invoked;
///
/// Initializes the action.
///
/// The action to execute once.
public SingleAction(Action action) => _action = action;
///
/// Invokes the action if not already invoked once.
///
public void Invoke()
{
if (_invoked)
return;
_action.Invoke();
_invoked = true;
}
}
}