magicmanam.UndoRedo 1.1.3

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package magicmanam.UndoRedo --version 1.1.3
NuGet\Install-Package magicmanam.UndoRedo -Version 1.1.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="magicmanam.UndoRedo" Version="1.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add magicmanam.UndoRedo --version 1.1.3
#r "nuget: magicmanam.UndoRedo, 1.1.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install magicmanam.UndoRedo as a Cake Addin
#addin nuget:?package=magicmanam.UndoRedo&version=1.1.3

// Install magicmanam.UndoRedo as a Cake Tool
#tool nuget:?package=magicmanam.UndoRedo&version=1.1.3

magicmanam.UndoRedo

magicmanam.UndoRedo nuget package is easy and lightweight Undo/Redo operations implementation

In order to add it to your solution, run Install-Package magicmanam.UndoRedo from your NuGet Package Manager console in Visual Studio.

Quick start

  1. Define class which will represent your application state at any time (for example AppState class)
  2. Implement interface <i>IStatefulComponent<AppState></i> to have possibility to retrieve current application state
  3. Initialize current undoable context for your application state:
UndoableContext<AppState>.Current = new UndoableContext<AppState>(statefulComponentInstance);
  1. Wrap any action which changes application state with the following code:
using (var action = UndoableContext<AppState>.Current.StartAction("Sample action name"))
{
	statefulComponentInstance.ChangeState();
	// action.Cancel(); - you can cancel your application state change and the previous state will be restored
}
  1. Now you can undo/redo any your action made in scope of current undoable context:
UndoableContext<AppState>.Current.Undo();
// statefulComponentInstance returns the previous state now
// or
UndoableContext<AppState>.Current.Redo();
// Rollbacks the previous Undo operation
  1. You can subscribe on any action in scope of the current undoable context including cancelled actions and Undo/Redo operations:
UndoableContext<AppState>.Current.UndoableAction += (object sender, UndoableActionEventArgs<AppState> e) =>
{
    if (e.Action.IsCancelled)
    {
        // Action was cancelled
    }
    else
    {
        if (e.IsUndo)
        {
             // The latest action was undone
        }
        else if (e.IsRedo)
        {
             // The latest undo operation was restored
        }
        else
        {
	     // e.Action.Name == "Sample action name"
             // Ordinary action on application state was performed
        }
    }
};

Icon's source: https://www.shareicon.net/religion-philosophy-taoism-signs-yin-yang-balance-748079

Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3 439 5/25/2021
1.1.1 331 5/21/2021
1.1.0 344 5/18/2021
1.0.0.1 776 9/30/2018
1.0.0 928 5/25/2018

Removes icon from content