SnapshotManager 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SnapshotManager --version 1.1.0
                    
NuGet\Install-Package SnapshotManager -Version 1.1.0
                    
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="SnapshotManager" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SnapshotManager" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SnapshotManager" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SnapshotManager --version 1.1.0
                    
#r "nuget: SnapshotManager, 1.1.0"
                    
#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.
#:package SnapshotManager@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SnapshotManager&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SnapshotManager&version=1.1.0
                    
Install as a Cake Tool

SnapshotManager

SnapshotManager 是一个通用快照与差异管理工具,用于保存对象状态并计算对象差异(Diff),支持复杂对象结构,如二维数组。


核心接口与类

  • IDiff<T> 对象实现自定义差异计算:

    public interface IDiff<T>
    {
        DiffNode Diff(T oldValue, T newValue);
    }
    
  • ElementBase 通用基类,实现字段级自动 Diff:

    public abstract class ElementBase : IDiff<ElementBase>
    {
        public abstract ElementBase DeepClone();
        public virtual DiffNode Diff(ElementBase oldValue, ElementBase newValue) { ... }
    }
    
  • ElementArraySnapshot 保存二维列表快照:

    public class ElementArraySnapshot : Snapshot<List<List<ElementBase>>>
    {
        public ElementArraySnapshot(string name, string desc, List<List<ElementBase>> src)
            : base(name, desc, DeepClone2D(src)) { }
        private static List<List<ElementBase>> DeepClone2D(List<List<ElementBase>> src) => 
            src.Select(row => row.Select(e => e?.DeepClone()).ToList()).ToList();
    }
    
  • SnapshotManager<T> 管理快照并计算差异:

    var manager = new SnapshotManager<List<List<ElementBase>>>();
    manager.AddSnapshot("s1", snapshot1);
    manager.AddSnapshot("s2", snapshot2);
    var diff = manager.CompareSnapshots("s1", "s2");
    

使用示例

var elements = new List<List<ElementBase>> { new() { new MyElement { Value = 1 } } };
var snapshot1 = new ElementArraySnapshot("s1", "初始", elements);

// 修改后快照
elements[0][0] = new MyElement { Value = 10 };
var snapshot2 = new ElementArraySnapshot("s2", "修改后", elements);

// 管理与对比
var manager = new SnapshotManager<List<List<ElementBase>>>();
manager.AddSnapshot("s1", snapshot1);
manager.AddSnapshot("s2", snapshot2);
var diff = manager.CompareSnapshots("s1", "s2");
Console.WriteLine(diff);

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.7.2

  • net8.0

    • No dependencies.
  • net9.0

    • 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.2.2 112 3/24/2026
1.2.1 98 3/23/2026
1.2.0 99 3/23/2026
1.1.3 109 3/23/2026
1.1.1 95 3/22/2026
1.1.0 96 3/22/2026
1.0.0 675 12/3/2025

- Feat: 新增对多个 .NET 框架 (net9.0, net8.0, net472) 的支持。
- Fix: 解决了各种编译错误和可空引用类型警告。
- Build: 将项目文件升级到现代 SDK 风格并改进了包元数据。