public void Execute() { Debug.Assert(!hasExecuted); if (hasExecuted) { throw new InvalidOperationException(); } for (int i = 0; i < nodes.Length; i++) { var node = nodes[i]; var savedState = savedStates[i]; var module = node.Document.ModuleDef; bool b = module != null && module.Assembly == null; Debug.Assert(b); if (!b) { throw new InvalidOperationException(); } savedState.ModuleKind = module.Kind; ModuleUtils.AddToNewAssemblyDef(module, ModuleKind.Dll, out savedState.Characteristics); if (savedState.AssemblyFileNode == null) { var asmFile = DsDotNetDocument.CreateAssembly(node.Document); savedState.AssemblyFileNode = node.Context.DocumentTreeView.CreateAssembly(asmFile); } Debug.Assert(savedState.AssemblyFileNode.Document.Children.Count == 1); savedState.AssemblyFileNode.Document.Children.Remove(node.Document); Debug.Assert(savedState.AssemblyFileNode.Document.Children.Count == 0); savedState.AssemblyFileNode.TreeNode.EnsureChildrenLoaded(); Debug.Assert(savedState.AssemblyFileNode.TreeNode.Children.Count == 0); savedState.AssemblyFileNode.Document.Children.Add(node.Document); int index = node.Context.DocumentTreeView.TreeView.Root.DataChildren.ToList().IndexOf(node); b = index >= 0; Debug.Assert(b); if (!b) { throw new InvalidOperationException(); } node.Context.DocumentTreeView.TreeView.Root.Children[index] = savedState.AssemblyFileNode.TreeNode; savedState.AssemblyFileNode.TreeNode.AddChild(node.TreeNode); } hasExecuted = true; }
public void Execute() { Debug.Assert(savedStates == null); if (savedStates != null) { throw new InvalidOperationException(); } savedStates = new SavedState[nodes.Length]; for (int i = 0; i < nodes.Length; i++) { var node = nodes[i]; savedStates[i] = new SavedState(); var savedState = savedStates[i]; int index = node.TreeNode.Parent.Children.IndexOf(node.TreeNode); bool b = index >= 0; Debug.Assert(b); if (!b) { throw new InvalidOperationException(); } savedState.ModuleNode = (ModuleDocumentNode)node.TreeNode.Children.First(a => a.Data is ModuleDocumentNode).Data; node.TreeNode.Children.Remove(savedState.ModuleNode.TreeNode); node.TreeNode.Parent.Children[index] = savedState.ModuleNode.TreeNode; var module = node.Document.ModuleDef; b = module != null && module.Assembly != null && module.Assembly.Modules.Count == 1 && module.Assembly.ManifestModule == module; Debug.Assert(b); if (!b) { throw new InvalidOperationException(); } node.TreeNode.EnsureChildrenLoaded(); savedState.AssemblyDef = module.Assembly; module.Assembly.Modules.Remove(module); savedState.ModuleKind = module.Kind; ModuleUtils.WriteNewModuleKind(module, ModuleKind.NetModule, out savedState.Characteristics); } }
AddNewNetModuleToAssemblyCommand(AssemblyTreeNode asmNode, NetModuleOptions options) : base(asmNode, new AssemblyTreeNode(new LoadedAssembly(MainWindow.Instance.CurrentAssemblyList, ModuleUtils.CreateNetModule(options.Name, options.Mvid, options.ClrVersion))), true) { }
CreateNetModuleCommand(NetModuleOptions options) { var module = ModuleUtils.CreateNetModule(options.Name, options.Mvid, options.ClrVersion); this.asmNodeCreator = new AssemblyTreeNodeCreator(new LoadedAssembly(MainWindow.Instance.CurrentAssemblyList, module)); }
AddNewNetModuleToAssemblyCommand(AssemblyTreeNode asmNode, NetModuleOptions options) : base(asmNode, new AssemblyTreeNode(MainWindow.Instance.DnSpyFileList.CreateDnSpyFile(ModuleUtils.CreateNetModule(options.Name, options.Mvid, options.ClrVersion))), true) { }
CreateNetModuleCommand(NetModuleOptions options) { var module = ModuleUtils.CreateNetModule(options.Name, options.Mvid, options.ClrVersion); this.asmNodeCreator = new AssemblyTreeNodeCreator(MainWindow.Instance.DnSpyFileList.CreateDnSpyFile(module)); }