예제 #1
0
파일: Commands.cs 프로젝트: zhenren92/dnSpy
		internal static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, 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 is null));
			if (modNode is null)
				throw new InvalidOperationException();
			var module = modNode.Document.ModuleDef;
			Debug.Assert(!(module is null));
			if (module is null)
				throw new InvalidOperationException();

			using (var vm = editCodeVMCreator.CreateEditMethodCode(methodNode.MethodDef, statements ?? Array.Empty<MethodSourceStatement>())) {
				var win = new EditCodeDlg();
				win.DataContext = vm;
				win.Owner = appService.MainWindow;
				win.Title = $"{win.Title} - {methodNode.ToString()}";

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

				undoCommandService.Value.Add(new EditMethodBodyCodeCommand(addUpdatedNodesHelperProvider, modNode, vm.Result));
			}
		}
예제 #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.CreateEditMethodCode(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();
        }
예제 #3
0
		internal static void Execute(EditCodeVMCreator editCodeVMCreator, Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, 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.CreateEditMethodCode(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(addUpdatedNodesHelperProvider, modNode, vm.Result));
			vm.Dispose();
		}