示例#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();
        }
示例#2
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);
        }
示例#3
0
        FieldDefSettingsCommand(FieldNode fieldNode, FieldDefOptions options)
        {
            this.fieldNode   = fieldNode;
            this.newOptions  = options;
            this.origOptions = new FieldDefOptions(fieldNode.FieldDef);

            this.origParentNode       = (DocumentTreeNodeData)fieldNode.TreeNode.Parent.Data;
            this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(fieldNode.TreeNode);
            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(fieldNode.GetModule()).Where(a => RefFinder.FieldEqualityComparerInstance.Equals(a, fieldNode.FieldDef)).Select(a => new MemberRefInfo(a)).ToArray();
            }
        }
示例#4
0
 void InitializeFrom(FieldDefOptions options)
 {
     Attributes         = options.Attributes;
     Name               = options.Name;
     FieldTypeSig       = 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;
     }
     FieldAccess.SelectedItem = (Field.FieldAccess)((int)(options.Attributes & FieldAttributes.FieldAccessMask) >> 0);
     CustomAttributesVM.InitializeFrom(options.CustomAttributes);
 }
示例#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();
        }
示例#6
0
        public FieldOptionsVM(FieldDefOptions options, ModuleDef ownerModule, IDecompilerManager decompilerManager, TypeDef ownerType)
        {
            this.ownerModule = ownerModule;
            var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, decompilerManager)
            {
                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, decompilerManager);
            this.origOptions        = options;

            this.ConstantVM                = new ConstantVM(ownerModule, options.Constant?.Value, dnSpy_AsmEditor_Resources.Field_DefaultValueInfo);
            ConstantVM.PropertyChanged    += constantVM_PropertyChanged;
            this.MarshalTypeVM             = new MarshalTypeVM(ownerModule, decompilerManager, 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();
        }
示例#7
0
		public EditedField(FieldDef originalField, FieldDefOptions fieldDefOptions) {
			OriginalField = originalField;
			FieldDefOptions = fieldDefOptions;
		}
示例#8
0
 CreateFieldDefCommand(TypeTreeNode ownerNode, FieldDefOptions options)
 {
     this.ownerNode = ownerNode;
     this.fieldNode = new FieldTreeNode(options.CreateFieldDef(ownerNode.TypeDefinition.Module));
 }
示例#9
0
 CreateFieldDefCommand(TypeNode ownerNode, FieldDefOptions options)
 {
     this.ownerNode = ownerNode;
     this.fieldNode = ownerNode.Create(options.CreateFieldDef(ownerNode.TypeDef.Module));
 }
示例#10
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;
 }
示例#11
0
		FieldDefSettingsCommand(IFieldNode fieldNode, FieldDefOptions options) {
			this.fieldNode = fieldNode;
			this.newOptions = options;
			this.origOptions = new FieldDefOptions(fieldNode.FieldDef);

			this.origParentNode = (IFileTreeNodeData)fieldNode.TreeNode.Parent.Data;
			this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(fieldNode.TreeNode);
			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(fieldNode.GetModule()).Where(a => RefFinder.FieldEqualityComparerInstance.Equals(a, fieldNode.FieldDef)).Select(a => new MemberRefInfo(a)).ToArray();
		}
示例#12
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);
        }
示例#13
0
		CreateFieldDefCommand(ITypeNode ownerNode, FieldDefOptions options) {
			this.ownerNode = ownerNode;
			this.fieldNode = ownerNode.Create(options.CreateFieldDef(ownerNode.TypeDef.Module));
		}
示例#14
0
		public FieldOptionsVM(FieldDefOptions options, ModuleDef ownerModule, IDecompilerService decompilerService, TypeDef ownerType) {
			this.ownerModule = ownerModule;
			var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, decompilerService) {
				IsLocal = false,
				CanAddGenericTypeVar = true,
				CanAddGenericMethodVar = false,
				OwnerType = ownerType,
			};
			if (ownerType != null && ownerType.GenericParameters.Count == 0)
				typeSigCreatorOptions.CanAddGenericTypeVar = false;
			TypeSigCreator = new TypeSigCreatorVM(typeSigCreatorOptions);
			TypeSigCreator.PropertyChanged += typeSigCreator_PropertyChanged;

			CustomAttributesVM = new CustomAttributesVM(ownerModule, decompilerService);
			origOptions = options;

			ConstantVM = new ConstantVM(ownerModule, options.Constant?.Value, dnSpy_AsmEditor_Resources.Field_DefaultValueInfo);
			ConstantVM.PropertyChanged += constantVM_PropertyChanged;
			MarshalTypeVM = new MarshalTypeVM(ownerModule, decompilerService, ownerType, null);
			MarshalTypeVM.PropertyChanged += marshalTypeVM_PropertyChanged;
			FieldOffset = new NullableUInt32VM(a => HasErrorUpdated());
			InitialValue = new HexStringVM(a => HasErrorUpdated());
			RVA = new UInt32VM(a => HasErrorUpdated());
			ImplMapVM = new ImplMapVM(ownerModule);
			ImplMapVM.PropertyChanged += implMapVM_PropertyChanged;

			TypeSigCreator.CanAddFnPtr = false;
			ConstantVM.IsEnabled = HasDefault;
			MarshalTypeVM.IsEnabled = HasFieldMarshal;
			ImplMapVM.IsEnabled = PinvokeImpl;
			Reinitialize();
		}
示例#15
0
 CreateFieldDefCommand(TypeTreeNode ownerNode, FieldDefOptions options)
 {
     this.ownerNode = ownerNode;
     this.fieldNode = new FieldTreeNode(options.CreateFieldDef(ownerNode.TypeDefinition.Module));
 }
示例#16
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()));
        }
示例#17
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);
 }