public override void Execute(CodeContext context) => CreateFieldDefCommand.Execute(undoCommandService, appService, context.Nodes);
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); }
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); }
public override bool IsVisible(AsmEditorContext context) => CreateFieldDefCommand.CanExecute(context.Nodes);
protected override void ExecuteInternal(ILSpyTreeNode[] nodes) { CreateFieldDefCommand.Execute(nodes); }
protected override void Execute(Context ctx) { CreateFieldDefCommand.Execute(ctx.Nodes); }
protected override bool CanExecuteInternal(ILSpyTreeNode[] nodes) { return(CreateFieldDefCommand.CanExecute(nodes)); }
public override void Execute(CodeContext context) { CreateFieldDefCommand.Execute(undoCommandManager, appWindow, context.Nodes); }
public override void Execute(AsmEditorContext context) => CreateFieldDefCommand.Execute(undoCommandManager, appWindow, context.Nodes);
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.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, MainWindow.Instance.CurrentLanguage, type); var win = new FieldOptionsDlg(); win.Title = CMD_NAME; win.DataContext = data; win.Owner = MainWindow.Instance; if (win.ShowDialog() != true) return; var cmd = new CreateFieldDefCommand(typeNode, data.CreateFieldDefOptions()); UndoCommandManager.Instance.Add(cmd); MainWindow.Instance.JumpToReference(cmd.fieldNode); }
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.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, MainWindow.Instance.CurrentLanguage, type); var win = new FieldOptionsDlg(); win.Title = CMD_NAME; win.DataContext = data; win.Owner = MainWindow.Instance; if (win.ShowDialog() != true) { return; } var cmd = new CreateFieldDefCommand(typeNode, data.CreateFieldDefOptions()); UndoCommandManager.Instance.Add(cmd); MainWindow.Instance.JumpToReference(cmd.fieldNode); }