namespace UndoTree; internal static class UndoTreeArchive { public static IReadOnlyList Restore(UndoTreeRecord record) { var restored = new Dictionary(); var nodes = new List(); foreach (var item in record.Nodes.OrderBy(node => node.Id)) { restored.TryGetValue(item.Parent, out var parent); var commands = item.Commands .Select(command => new UndoTreeCommandInfo(Enum.TryParse(command.Kind, out var kind) ? kind : CommandKind.Other, null, command.Target, command.Member, command.Detail, null)) .ToArray(); var node = new UndoTreeNodeViewModel(item.Id, null, parent, item.Label, commands, item.Time, 0) { IsArchived = true, IsOnPath = true, Tag = item.Tag ?? string.Empty, IsSaved = item.Saved }; parent?.Children.Add(node); restored[item.Id] = node; nodes.Add(node); } return nodes; } }