Exemple #1
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 #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(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 #4
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()));
        }