Exemple #1
0
        static void Execute(Lazy <IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes)
        {
            if (!CanExecute(nodes))
            {
                return;
            }

            var fieldNode = (FieldNode)nodes[0];

            var module = nodes[0].GetModule();

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

            var data = new FieldOptionsVM(new FieldDefOptions(fieldNode.FieldDef), module, appService.DecompilerService, fieldNode.FieldDef.DeclaringType);
            var win  = new FieldOptionsDlg();

            win.DataContext = data;
            win.Owner       = appService.MainWindow;
            if (win.ShowDialog() != true)
            {
                return;
            }

            undoCommandService.Value.Add(new FieldDefSettingsCommand(fieldNode, data.CreateFieldDefOptions()));
        }
Exemple #2
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
            {
                return;
            }

            var fieldNode = (FieldTreeNode)nodes[0];

            var module = ILSpyTreeNode.GetModule(nodes[0]);

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

            var data = new FieldOptionsVM(new FieldDefOptions(fieldNode.FieldDefinition), module, MainWindow.Instance.CurrentLanguage, fieldNode.FieldDefinition.DeclaringType);
            var win  = new FieldOptionsDlg();

            win.DataContext = data;
            win.Owner       = MainWindow.Instance;
            if (win.ShowDialog() != true)
            {
                return;
            }

            UndoCommandManager.Instance.Add(new FieldDefSettingsCommand(fieldNode, data.CreateFieldDefOptions()));
        }
Exemple #3
0
        static void Execute(Lazy <IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes)
        {
            if (!CanExecute(nodes))
            {
                return;
            }

            var ownerNode = nodes[0];

            if (!(ownerNode is TypeNode))
            {
                ownerNode = (DocumentTreeNodeData)ownerNode.TreeNode.Parent.Data;
            }
            var typeNode = ownerNode as TypeNode;

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

            var module = typeNode.GetModule();

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

            FieldDefOptions options;
            var             type = typeNode.TypeDef;

            if (type.IsEnum)
            {
                var ts = type.GetEnumUnderlyingType();
                if (ts != null)
                {
                    options             = FieldDefOptions.Create("MyField", new FieldSig(new ValueTypeSig(typeNode.TypeDef)));
                    options.Constant    = module.UpdateRowId(new ConstantUser(ModelUtils.GetDefaultValue(ts), ts.RemovePinnedAndModifiers().GetElementType()));
                    options.Attributes |= FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.HasDefault;
                }
                else
                {
                    options             = FieldDefOptions.Create("value__", new FieldSig(module.CorLibTypes.Int32));
                    options.Attributes |= FieldAttributes.SpecialName | FieldAttributes.RTSpecialName;
                }
            }
            else if (type.IsAbstract && type.IsSealed)
            {
                options             = FieldDefOptions.Create("MyField", new FieldSig(module.CorLibTypes.Int32));
                options.Attributes |= FieldAttributes.Static;
            }
            else
            {
                options = FieldDefOptions.Create("MyField", new FieldSig(module.CorLibTypes.Int32));
            }

            var data = new FieldOptionsVM(options, module, appService.DecompilerService, type);
            var win  = new FieldOptionsDlg();

            win.Title       = dnSpy_AsmEditor_Resources.CreateFieldCommand2;
            win.DataContext = data;
            win.Owner       = appService.MainWindow;
            if (win.ShowDialog() != true)
            {
                return;
            }

            var cmd = new CreateFieldDefCommand(typeNode, data.CreateFieldDefOptions());

            undoCommandService.Value.Add(cmd);
            appService.DocumentTabService.FollowReference(cmd.fieldNode);
        }
Exemple #4
0
		static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var fieldNode = (IFieldNode)nodes[0];

			var module = nodes[0].GetModule();
			Debug.Assert(module != null);
			if (module == null)
				throw new InvalidOperationException();

			var data = new FieldOptionsVM(new FieldDefOptions(fieldNode.FieldDef), module, appWindow.LanguageManager, fieldNode.FieldDef.DeclaringType);
			var win = new FieldOptionsDlg();
			win.DataContext = data;
			win.Owner = appWindow.MainWindow;
			if (win.ShowDialog() != true)
				return;

			undoCommandManager.Value.Add(new FieldDefSettingsCommand(fieldNode, data.CreateFieldDefOptions()));
		}
Exemple #5
0
		static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var ownerNode = nodes[0];
			if (!(ownerNode is ITypeNode))
				ownerNode = (IFileTreeNodeData)ownerNode.TreeNode.Parent.Data;
			var typeNode = ownerNode as ITypeNode;
			Debug.Assert(typeNode != null);
			if (typeNode == null)
				throw new InvalidOperationException();

			var module = typeNode.GetModule();
			Debug.Assert(module != null);
			if (module == null)
				throw new InvalidOperationException();

			FieldDefOptions options;
			var type = typeNode.TypeDef;
			if (type.IsEnum) {
				var ts = type.GetEnumUnderlyingType();
				if (ts != null) {
					options = FieldDefOptions.Create("MyField", new FieldSig(new ValueTypeSig(typeNode.TypeDef)));
					options.Constant = module.UpdateRowId(new ConstantUser(ModelUtils.GetDefaultValue(ts), ts.RemovePinnedAndModifiers().GetElementType()));
					options.Attributes |= FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.HasDefault;
				}
				else {
					options = FieldDefOptions.Create("value__", new FieldSig(module.CorLibTypes.Int32));
					options.Attributes |= FieldAttributes.SpecialName | FieldAttributes.RTSpecialName;
				}
			}
			else if (type.IsAbstract && type.IsSealed) {
				options = FieldDefOptions.Create("MyField", new FieldSig(module.CorLibTypes.Int32));
				options.Attributes |= FieldAttributes.Static;
			}
			else
				options = FieldDefOptions.Create("MyField", new FieldSig(module.CorLibTypes.Int32));

			var data = new FieldOptionsVM(options, module, appWindow.LanguageManager, type);
			var win = new FieldOptionsDlg();
			win.Title = dnSpy_AsmEditor_Resources.CreateFieldCommand2;
			win.DataContext = data;
			win.Owner = appWindow.MainWindow;
			if (win.ShowDialog() != true)
				return;

			var cmd = new CreateFieldDefCommand(typeNode, data.CreateFieldDefOptions());
			undoCommandManager.Value.Add(cmd);
			appWindow.FileTabManager.FollowReference(cmd.fieldNode);
		}
Exemple #6
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
            {
                return;
            }

            var ownerNode = nodes[0];

            if (!(ownerNode is TypeTreeNode))
            {
                ownerNode = (ILSpyTreeNode)ownerNode.Parent;
            }
            var typeNode = ownerNode as TypeTreeNode;

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

            var module = ILSpyTreeNode.GetModule(typeNode);

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

            FieldDefOptions options;
            var             type = typeNode.TypeDefinition;

            if (type.IsEnum)
            {
                var ts = type.GetEnumUnderlyingType();
                if (ts != null)
                {
                    options             = FieldDefOptions.Create("MyField", new FieldSig(new ValueTypeSig(typeNode.TypeDefinition)));
                    options.Constant    = module.UpdateRowId(new ConstantUser(ModelUtils.GetDefaultValue(ts), ts.RemovePinnedAndModifiers().GetElementType()));
                    options.Attributes |= FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.HasDefault;
                }
                else
                {
                    options             = FieldDefOptions.Create("value__", new FieldSig(module.CorLibTypes.Int32));
                    options.Attributes |= FieldAttributes.SpecialName | FieldAttributes.RTSpecialName;
                }
            }
            else if (type.IsAbstract && type.IsSealed)
            {
                options             = FieldDefOptions.Create("MyField", new FieldSig(module.CorLibTypes.Int32));
                options.Attributes |= FieldAttributes.Static;
            }
            else
            {
                options = FieldDefOptions.Create("MyField", new FieldSig(module.CorLibTypes.Int32));
            }

            var data = new FieldOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, type);
            var win  = new FieldOptionsDlg();

            win.Title       = "Create Field";
            win.DataContext = data;
            win.Owner       = MainWindow.Instance;
            if (win.ShowDialog() != true)
            {
                return;
            }

            UndoCommandManager.Instance.Add(new CreateFieldDefCommand(typeNode, data.CreateFieldDefOptions()));
        }
Exemple #7
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var fieldNode = (FieldTreeNode)nodes[0];

            var module = ILSpyTreeNode.GetModule(nodes[0]);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();

            var data = new FieldOptionsVM(new FieldDefOptions(fieldNode.FieldDefinition), module, MainWindow.Instance.CurrentLanguage, fieldNode.FieldDefinition.DeclaringType);
            var win = new FieldOptionsDlg();
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            UndoCommandManager.Instance.Add(new FieldDefSettingsCommand(fieldNode, data.CreateFieldDefOptions()));
        }
Exemple #8
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var ownerNode = nodes[0];
            if (!(ownerNode is TypeTreeNode))
                ownerNode = (ILSpyTreeNode)ownerNode.Parent;
            var typeNode = ownerNode as TypeTreeNode;
            Debug.Assert(typeNode != null);
            if (typeNode == null)
                throw new InvalidOperationException();

            var module = ILSpyTreeNode.GetModule(typeNode);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();

            FieldDefOptions options;
            var type = typeNode.TypeDefinition;
            if (type.IsEnum) {
                var ts = type.GetEnumUnderlyingType();
                if (ts != null) {
                    options = FieldDefOptions.Create("MyField", new FieldSig(new ValueTypeSig(typeNode.TypeDefinition)));
                    options.Constant = module.UpdateRowId(new ConstantUser(ModelUtils.GetDefaultValue(ts), ts.RemovePinnedAndModifiers().GetElementType()));
                    options.Attributes |= FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.HasDefault;
                }
                else {
                    options = FieldDefOptions.Create("value__", new FieldSig(module.CorLibTypes.Int32));
                    options.Attributes |= FieldAttributes.SpecialName | FieldAttributes.RTSpecialName;
                }
            }
            else if (type.IsAbstract && type.IsSealed) {
                options = FieldDefOptions.Create("MyField", new FieldSig(module.CorLibTypes.Int32));
                options.Attributes |= FieldAttributes.Static;
            }
            else
                options = FieldDefOptions.Create("MyField", new FieldSig(module.CorLibTypes.Int32));

            var data = new FieldOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, type);
            var win = new FieldOptionsDlg();
            win.Title = "Create Field";
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            UndoCommandManager.Instance.Add(new CreateFieldDefCommand(typeNode, data.CreateFieldDefOptions()));
        }