public static void Serialize(CmdProject prj, Stream stream)
        {
            if (prj == null)
            {
                throw new ArgumentNullException(nameof(prj));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            var data = new ProjectDataJsonVersioned
            {
                Id            = prj.Id,
                ExclusiveMode = prj.ExclusiveMode,
                Delimiter     = prj.Delimiter,
                Items         = TransformCmdList(prj.Items)
            };

            string jsonStr = JsonConvert.SerializeObject(data, Formatting.Indented);

            StreamWriter sw = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));

            sw.Write(jsonStr);
            sw.Flush();
        }
        public static SuoDataJson Serialize(ToolWindowViewModel vm)
        {
            if (vm == null)
            {
                throw new ArgumentNullException(nameof(vm));
            }

            var data = new SuoDataJson();

            data.ShowAllProjects   = vm.TreeViewModel.ShowAllProjects;
            data.CheckedArguments  = new HashSet <Guid>(vm.TreeViewModel.AllProjects.SelectMany(p => p.CheckedArguments).Select(arg => arg.Id));
            data.ExpandedContainer = new HashSet <Guid>(vm.TreeViewModel.AllItems.OfType <CmdContainer>().Where(con => con.IsExpanded).Select(p => p.Id));

            data.SelectedItems = new HashSet <Guid>(vm.TreeViewModel.Projects.Values.SelectMany(p => p.SelectedItems).Select(item => item.Id)
                                                    .Concat(vm.TreeViewModel.Projects.Values.Where(p => p.IsSelected).Select(p => p.Id)));

            foreach (var kvPair in vm.TreeViewModel.Projects)
            {
                var list = new ProjectDataJsonVersioned
                {
                    Id            = kvPair.Value.Id,
                    ExclusiveMode = kvPair.Value.ExclusiveMode,
                    Delimiter     = kvPair.Value.Delimiter,
                    Items         = TransformCmdList(kvPair.Value.Items),

                    // not in JSON
                    Expanded = kvPair.Value.IsExpanded,
                    Selected = kvPair.Value.IsSelected,
                };
                data.ProjectArguments.Add(kvPair.Key, list);
            }

            return(data);
        }