Esempio n. 1
0
        public FieldOptionsVM(FieldDefOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType)
        {
            this.ownerModule = ownerModule;
            var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language) {
                IsLocal = false,
                CanAddGenericTypeVar = true,
                CanAddGenericMethodVar = false,
                OwnerType = ownerType,
            };
            if (ownerType != null && ownerType.GenericParameters.Count == 0)
                typeSigCreatorOptions.CanAddGenericTypeVar = false;
            this.typeSigCreator = new TypeSigCreatorVM(typeSigCreatorOptions);
            TypeSigCreator.PropertyChanged += typeSigCreator_PropertyChanged;

            this.customAttributesVM = new CustomAttributesVM(ownerModule, language);
            this.origOptions = options;

            this.constantVM = new ConstantVM(ownerModule, options.Constant == null ? null : options.Constant.Value, "Default value for this field");
            ConstantVM.PropertyChanged += constantVM_PropertyChanged;
            this.marshalTypeVM = new MarshalTypeVM(ownerModule, language, ownerType, null);
            MarshalTypeVM.PropertyChanged += marshalTypeVM_PropertyChanged;
            this.fieldOffset = new NullableUInt32VM(a => HasErrorUpdated());
            this.initialValue = new HexStringVM(a => HasErrorUpdated());
            this.rva = new UInt32VM(a => HasErrorUpdated());
            this.implMapVM = new ImplMapVM(ownerModule);
            ImplMapVM.PropertyChanged += implMapVM_PropertyChanged;

            this.typeSigCreator.CanAddFnPtr = false;
            ConstantVM.IsEnabled = HasDefault;
            MarshalTypeVM.IsEnabled = HasFieldMarshal;
            ImplMapVM.IsEnabled = PinvokeImpl;
            Reinitialize();
        }
Esempio n. 2
0
        FieldDefSettingsCommand(FieldTreeNode fieldNode, FieldDefOptions options)
        {
            this.fieldNode   = fieldNode;
            this.newOptions  = options;
            this.origOptions = new FieldDefOptions(fieldNode.FieldDefinition);

            this.origParentNode       = (ILSpyTreeNode)fieldNode.Parent;
            this.origParentChildIndex = this.origParentNode.Children.IndexOf(fieldNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
            {
                throw new InvalidOperationException();
            }

            this.nameChanged = origOptions.Name != newOptions.Name;
        }
Esempio n. 3
0
        FieldDefOptions CopyTo(FieldDefOptions options)
        {
            options.Attributes = Attributes;
            options.Name       = Name;
            var typeSig = FieldTypeSig;

            options.FieldSig     = typeSig == null ? null : new FieldSig(typeSig);
            options.FieldOffset  = FieldOffset.Value;
            options.MarshalType  = HasFieldMarshal ? MarshalTypeVM.Type : null;
            options.RVA          = (dnlib.PE.RVA)RVA.Value;
            options.InitialValue = HasFieldRVA ? InitialValue.Value.ToArray() : null;
            options.ImplMap      = PinvokeImpl ? ImplMap : null;
            options.Constant     = HasDefault ? Constant : null;
            options.CustomAttributes.Clear();
            options.CustomAttributes.AddRange(CustomAttributesVM.Collection.Select(a => a.CreateCustomAttributeOptions().Create()));
            return(options);
        }
Esempio n. 4
0
 void InitializeFrom(FieldDefOptions options)
 {
     Attributes         = options.Attributes;
     Name               = options.Name;
     FieldTypeSig       = options.FieldSig == null ? null : options.FieldSig.Type;
     FieldOffset.Value  = options.FieldOffset;
     MarshalTypeVM.Type = options.MarshalType;
     RVA.Value          = (uint)options.RVA;
     InitialValue.Value = options.InitialValue;
     ImplMap            = options.ImplMap;
     if (options.Constant != null)
     {
         HasDefault       = true;
         ConstantVM.Value = options.Constant.Value;
     }
     else
     {
         HasDefault       = false;
         ConstantVM.Value = null;
     }
     FieldVisibility.SelectedItem = (Field.FieldVisibility)((int)(options.Attributes & FieldAttributes.FieldAccessMask) >> 0);
     CustomAttributesVM.InitializeFrom(options.CustomAttributes);
 }
Esempio n. 5
0
        public FieldOptionsVM(FieldDefOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType)
        {
            this.ownerModule = ownerModule;
            var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language)
            {
                IsLocal = false,
                CanAddGenericTypeVar   = true,
                CanAddGenericMethodVar = false,
                OwnerType = ownerType,
            };

            if (ownerType != null && ownerType.GenericParameters.Count == 0)
            {
                typeSigCreatorOptions.CanAddGenericTypeVar = false;
            }
            this.typeSigCreator             = new TypeSigCreatorVM(typeSigCreatorOptions);
            TypeSigCreator.PropertyChanged += typeSigCreator_PropertyChanged;

            this.customAttributesVM = new CustomAttributesVM(ownerModule, language);
            this.origOptions        = options;

            this.constantVM                = new ConstantVM(ownerModule, options.Constant == null ? null : options.Constant.Value, "Default value for this field");
            ConstantVM.PropertyChanged    += constantVM_PropertyChanged;
            this.marshalTypeVM             = new MarshalTypeVM(ownerModule, language, ownerType, null);
            MarshalTypeVM.PropertyChanged += marshalTypeVM_PropertyChanged;
            this.fieldOffset               = new NullableUInt32VM(a => HasErrorUpdated());
            this.initialValue              = new HexStringVM(a => HasErrorUpdated());
            this.rva                   = new UInt32VM(a => HasErrorUpdated());
            this.implMapVM             = new ImplMapVM(ownerModule);
            ImplMapVM.PropertyChanged += implMapVM_PropertyChanged;

            this.typeSigCreator.CanAddFnPtr = false;
            ConstantVM.IsEnabled            = HasDefault;
            MarshalTypeVM.IsEnabled         = HasFieldMarshal;
            ImplMapVM.IsEnabled             = PinvokeImpl;
            Reinitialize();
        }
Esempio n. 6
0
 CreateFieldDefCommand(TypeTreeNode ownerNode, FieldDefOptions options)
 {
     this.ownerNode = ownerNode;
     this.fieldNode = new FieldTreeNode(options.CreateFieldDef(ownerNode.TypeDefinition.Module));
 }
Esempio n. 7
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()));
        }
Esempio n. 8
0
 CreateFieldDefCommand(TypeTreeNode ownerNode, FieldDefOptions options)
 {
     this.ownerNode = ownerNode;
     this.fieldNode = new FieldTreeNode(options.CreateFieldDef(ownerNode.TypeDefinition.Module));
 }
Esempio n. 9
0
        FieldDefSettingsCommand(FieldTreeNode fieldNode, FieldDefOptions options)
        {
            this.fieldNode = fieldNode;
            this.newOptions = options;
            this.origOptions = new FieldDefOptions(fieldNode.FieldDefinition);

            this.origParentNode = (ILSpyTreeNode)fieldNode.Parent;
            this.origParentChildIndex = this.origParentNode.Children.IndexOf(fieldNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
                throw new InvalidOperationException();

            this.nameChanged = origOptions.Name != newOptions.Name;
            if (this.nameChanged)
                this.memberRefInfos = RefFinder.FindMemberRefsToThisModule(ILSpyTreeNode.GetModule(fieldNode)).Where(a => RefFinder.FieldEqualityComparerInstance.Equals(a, fieldNode.FieldDefinition)).Select(a => new MemberRefInfo(a)).ToArray();
        }
Esempio n. 10
0
 void InitializeFrom(FieldDefOptions options)
 {
     Attributes = options.Attributes;
     Name = options.Name;
     FieldTypeSig = options.FieldSig == null ? null : options.FieldSig.Type;
     FieldOffset.Value = options.FieldOffset;
     MarshalTypeVM.Type = options.MarshalType;
     RVA.Value = (uint)options.RVA;
     InitialValue.Value = options.InitialValue;
     ImplMap = options.ImplMap;
     if (options.Constant != null) {
         HasDefault = true;
         ConstantVM.Value = options.Constant.Value;
     }
     else {
         HasDefault = false;
         ConstantVM.Value = null;
     }
     FieldVisibility.SelectedItem = (Field.FieldVisibility)((int)(options.Attributes & FieldAttributes.FieldAccessMask) >> 0);
     CustomAttributesVM.InitializeFrom(options.CustomAttributes);
 }
Esempio n. 11
0
 FieldDefOptions CopyTo(FieldDefOptions options)
 {
     options.Attributes = Attributes;
     options.Name = Name;
     var typeSig = FieldTypeSig;
     options.FieldSig = typeSig == null ? null : new FieldSig(typeSig);
     options.FieldOffset = FieldOffset.Value;
     options.MarshalType = HasFieldMarshal ? MarshalTypeVM.Type : null;
     options.RVA = (dnlib.PE.RVA)RVA.Value;
     options.InitialValue = HasFieldRVA ? InitialValue.Value.ToArray() : null;
     options.ImplMap = PinvokeImpl ? ImplMap : null;
     options.Constant = HasDefault ? Constant : null;
     options.CustomAttributes.Clear();
     options.CustomAttributes.AddRange(CustomAttributesVM.Collection.Select(a => a.CreateCustomAttributeOptions().Create()));
     return options;
 }
Esempio n. 12
0
        FieldDefSettingsCommand(FieldTreeNode fieldNode, FieldDefOptions options)
        {
            this.fieldNode = fieldNode;
            this.newOptions = options;
            this.origOptions = new FieldDefOptions(fieldNode.FieldDefinition);

            this.origParentNode = (ILSpyTreeNode)fieldNode.Parent;
            this.origParentChildIndex = this.origParentNode.Children.IndexOf(fieldNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
                throw new InvalidOperationException();

            this.nameChanged = origOptions.Name != newOptions.Name;
        }