예제 #1
0
        internal static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy <IMethodAnnotations> methodAnnotations, Lazy <IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeNodeData[] nodes, uint[] offsets = null)
        {
            if (!CanExecute(editCodeVMCreator, nodes))
            {
                return;
            }

            var methodNode = (IMethodNode)nodes[0];
            var modNode    = methodNode.GetModuleNode();

            Debug.Assert(modNode != null);
            if (modNode == null)
            {
                throw new InvalidOperationException();
            }
            var module = modNode.DnSpyFile.ModuleDef;

            Debug.Assert(module != null);
            if (module == null)
            {
                throw new InvalidOperationException();
            }

            var vm  = editCodeVMCreator.Create(methodNode.MethodDef);
            var win = new EditCodeDlg();

            win.DataContext = vm;
            win.Owner       = appWindow.MainWindow;
            win.Title       = string.Format("{0} - {1}", win.Title, methodNode.ToString());

            if (win.ShowDialog() != true)
            {
                vm.Dispose();
                return;
            }
            Debug.Assert(vm.Result != null);

            undoCommandManager.Value.Add(new EditMethodBodyCodeCommand(methodAnnotations, modNode, vm.Result));
            vm.Dispose();
        }
예제 #2
0
        internal static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy <IMethodAnnotations> methodAnnotations, Lazy <IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes, IList <MethodSourceStatement> statements = null)
        {
            if (!CanExecute(editCodeVMCreator, nodes))
            {
                return;
            }

            var methodNode = (MethodNode)nodes[0];
            var modNode    = methodNode.GetModuleNode();

            Debug.Assert(modNode != null);
            if (modNode == null)
            {
                throw new InvalidOperationException();
            }
            var module = modNode.Document.ModuleDef;

            Debug.Assert(module != null);
            if (module == null)
            {
                throw new InvalidOperationException();
            }

            var vm  = editCodeVMCreator.Create(methodNode.MethodDef, statements ?? Array.Empty <MethodSourceStatement>());
            var win = new EditCodeDlg();

            win.DataContext = vm;
            win.Owner       = appService.MainWindow;
            win.Title       = string.Format("{0} - {1}", win.Title, methodNode.ToString());

            if (win.ShowDialog() != true)
            {
                vm.Dispose();
                return;
            }
            Debug.Assert(vm.Result != null);

            undoCommandService.Value.Add(new EditMethodBodyCodeCommand(methodAnnotations, modNode, vm.Result));
            vm.Dispose();
        }