Exemplo n.º 1
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
            {
                return;
            }

            var    nsNode = ILSpyTreeNode.GetNode <NamespaceTreeNode>(nodes[0]);
            string ns     = nsNode == null ? string.Empty : nsNode.Name;

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

            Debug.Assert(module != null);
            if (module == null)
            {
                throw new InvalidOperationException();
            }
            var options = TypeDefOptions.Create(ns, TypeConstants.DEFAULT_TYPE_NAME, module.CorLibTypes.Object.TypeDefOrRef, false);

            var data = new TypeOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, null);
            var win  = new TypeOptionsDlg();

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

            var cmd = new CreateTypeDefCommand(module.Types, nodes[0], data.CreateTypeDefOptions());

            UndoCommandManager.Instance.Add(cmd);
            MainWindow.Instance.JumpToReference(cmd.typeNode);
        }
Exemplo n.º 2
0
        TypeDefSettingsCommand(ModuleDef module, ITypeNode typeNode, TypeDefOptions options)
        {
            this.module      = module;
            this.typeNode    = typeNode;
            this.newOptions  = options;
            this.origOptions = new TypeDefOptions(typeNode.TypeDef);

            this.origParentNode       = (IFileTreeNodeData)typeNode.TreeNode.Parent.Data;
            this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(typeNode.TreeNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
            {
                throw new InvalidOperationException();
            }

            this.nameChanged = origOptions.Name != newOptions.Name;
            if (this.origParentNode is INamespaceNode)
            {
                var modNode = (IModuleFileNode)this.origParentNode.TreeNode.Parent.Data;
                if (newOptions.Namespace != origOptions.Namespace)
                {
                    this.nsNodeCreator = new NamespaceNodeCreator(newOptions.Namespace, modNode);
                }
            }

            if (this.nameChanged || origOptions.Namespace != newOptions.Namespace)
            {
                this.typeRefInfos = RefFinder.FindTypeRefsToThisModule(module).Where(a => RefFinder.TypeEqualityComparerInstance.Equals(a, typeNode.TypeDef)).Select(a => new TypeRefInfo(a)).ToArray();
            }
        }
Exemplo n.º 3
0
        static void Execute(Lazy <IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeNodeData[] nodes)
        {
            if (!CanExecute(nodes))
            {
                return;
            }

            var    nsNode = nodes[0].GetAncestorOrSelf <INamespaceNode>();
            string ns     = nsNode?.Name ?? string.Empty;

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

            Debug.Assert(module != null);
            if (module == null)
            {
                throw new InvalidOperationException();
            }
            var options = TypeDefOptions.Create(ns, TypeConstants.DEFAULT_TYPE_NAME, module.CorLibTypes.Object.TypeDefOrRef, false);

            var data = new TypeOptionsVM(options, module, appWindow.LanguageManager, null);
            var win  = new TypeOptionsDlg();

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

            var cmd = new CreateTypeDefCommand(module.Types, nodes[0], data.CreateTypeDefOptions());

            undoCommandManager.Value.Add(cmd);
            appWindow.FileTabManager.FollowReference(cmd.typeNode);
        }
Exemplo n.º 4
0
 TypeDefOptions CopyTo(TypeDefOptions options)
 {
     options.Attributes  = Attributes;
     options.Namespace   = Namespace;
     options.Name        = Name;
     options.PackingSize = PackingSize.Value;
     options.ClassSize   = ClassSize.Value;
     options.BaseType    = BaseTypeSig.ToTypeDefOrRef();
     options.CustomAttributes.Clear();
     options.CustomAttributes.AddRange(CustomAttributesVM.Collection.Select(a => a.CreateCustomAttributeOptions().Create()));
     options.DeclSecurities.Clear();
     options.DeclSecurities.AddRange(DeclSecuritiesVM.Collection.Select(a => a.CreateDeclSecurityOptions().Create(ownerModule)));
     options.GenericParameters.Clear();
     options.GenericParameters.AddRange(GenericParamsVM.Collection.Select(a => a.CreateGenericParamOptions().Create(ownerModule)));
     options.Interfaces.Clear();
     options.Interfaces.AddRange(InterfaceImplsVM.Collection.Select(a => a.CreateTypeDefOrRefAndCAOptions().CreateInterfaceImpl(ownerModule)));
     if (ModelUtils.GetHasSecurityBit(options.DeclSecurities, options.CustomAttributes))
     {
         options.Attributes |= TypeAttributes.HasSecurity;
     }
     else
     {
         options.Attributes &= ~TypeAttributes.HasSecurity;
     }
     return(options);
 }
Exemplo n.º 5
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();
			var options = TypeDefOptions.Create(UTF8String.Empty, TypeConstants.DEFAULT_TYPE_NAME, module.CorLibTypes.Object.TypeDefOrRef, true);

			var data = new TypeOptionsVM(options, module, appService.DecompilerService, null);
			var win = new TypeOptionsDlg();
			win.Title = dnSpy_AsmEditor_Resources.CreateNestedTypeCommand2;
			win.DataContext = data;
			win.Owner = appService.MainWindow;
			if (win.ShowDialog() != true)
				return;

			var cmd = new CreateNestedTypeDefCommand(typeNode, data.CreateTypeDefOptions());
			undoCommandService.Value.Add(cmd);
			appService.DocumentTabService.FollowReference(cmd.nestedType);
		}
Exemplo n.º 6
0
		public ExistingTypeNodeUpdater(Lazy<IMethodAnnotations> methodAnnotations, ModuleDocumentNode modNode, MergedImportedType type) {
			targetType = type.TargetType;
			ownerModule = targetType.Module;
			origTypeDefOptions = new TypeDefOptions(targetType);
			newTypeDefOptions = type.NewTypeDefOptions;
			typeNode = modNode.Context.DocumentTreeView.FindNode(targetType);
			if (typeNode == null)
				throw new InvalidOperationException();
			nestedTypes1 = type.NewOrExistingNestedTypes.OfType<MergedImportedType>().Select(a => new ExistingTypeNodeUpdater(methodAnnotations, modNode, a)).ToArray();
			nestedTypes2 = type.NewOrExistingNestedTypes.OfType<NewImportedType>().Select(a => new NestedTypeNodeCreator(modNode, typeNode, a.TargetType)).ToArray();
			if (nestedTypes1.Length + nestedTypes2.Length != type.NewOrExistingNestedTypes.Count)
				throw new InvalidOperationException();
			fields = type.NewFields.Select(a => new FieldNodeCreator(modNode, typeNode, a)).ToArray();
			var specialMethods = GetSpecialMethods(type);
			methods = type.NewMethods.Where(a => !specialMethods.Contains(a)).Select(a => new MethodNodeCreator(modNode, typeNode, a)).ToArray();
			events = type.NewEvents.Select(a => new EventNodeCreator(modNode, typeNode, a)).ToArray();
			properties = type.NewProperties.Select(a => new PropertyNodeCreator(modNode, typeNode, a)).ToArray();
			editedFields = type.EditedFields.Select(a => new EditedFieldUpdater(modNode, a.OriginalField, a.FieldDefOptions)).ToArray();
			editedMethods = type.EditedMethods.Select(a => new EditedMethodUpdater(methodAnnotations, modNode, a.OriginalMethod, a.NewBody, a.MethodDefOptions)).ToArray();
			editedProperties = type.EditedProperties.Select(a => new EditedPropertyUpdater(modNode, a.OriginalProperty, a.PropertyDefOptions)).ToArray();
			editedEvents = type.EditedEvents.Select(a => new EditedEventUpdater(modNode, a.OriginalEvent, a.EventDefOptions)).ToArray();
			deletedTypes = type.DeletedNestedTypes.Select(a => new DeletedTypeUpdater(modNode, a)).ToArray();
			deletedFields = type.DeletedFields.Select(a => new DeletedFieldUpdater(modNode, a)).ToArray();
			deletedMethods = type.DeletedMethods.Select(a => new DeletedMethodUpdater(modNode, a)).ToArray();
			deletedProperties = type.DeletedProperties.Select(a => new DeletedPropertyUpdater(modNode, a)).ToArray();
			deletedEvents = type.DeletedEvents.Select(a => new DeletedEventUpdater(modNode, a)).ToArray();
		}
Exemplo n.º 7
0
        TypeDefSettingsCommand(ModuleDef module, TypeTreeNode typeNode, TypeDefOptions options)
        {
            this.module      = module;
            this.typeNode    = typeNode;
            this.newOptions  = options;
            this.origOptions = new TypeDefOptions(typeNode.TypeDefinition);

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

            this.nameChanged = origOptions.Name != newOptions.Name;
            if (this.origParentNode is NamespaceTreeNode)
            {
                var asmNode = (AssemblyTreeNode)this.origParentNode.Parent;
                if (!AssemblyTreeNode.NamespaceStringEqualsComparer.Equals(newOptions.Namespace, origOptions.Namespace))
                {
                    this.nsNodeCreator = new NamespaceTreeNodeCreator(newOptions.Namespace, asmNode);
                }
            }

            if (this.nameChanged || origOptions.Namespace != newOptions.Namespace)
            {
                this.typeRefInfos = RefFinder.FindTypeRefsToThisModule(module).Where(a => RefFinder.TypeEqualityComparerInstance.Equals(a, typeNode.TypeDefinition)).Select(a => new TypeRefInfo(a)).ToArray();
            }
        }
Exemplo n.º 8
0
		CreateNestedTypeDefCommand(TypeNode ownerType, TypeDefOptions options) {
			this.ownerType = ownerType;

			var modNode = ownerType.GetModuleNode();
			Debug.Assert(modNode != null);
			if (modNode == null)
				throw new InvalidOperationException();
			nestedType = ownerType.Create(options.CreateTypeDef(modNode.Document.ModuleDef));
		}
Exemplo n.º 9
0
		CreateTypeDefCommand(IList<TypeDef> ownerList, DocumentTreeNodeData ownerNode, TypeDefOptions options) {
			this.ownerList = ownerList;
			var modNode = ownerNode.GetModuleNode();
			Debug.Assert(modNode != null);
			if (modNode == null)
				throw new InvalidOperationException();
			nsNodeCreator = new NamespaceNodeCreator(options.Namespace, modNode);
			typeNode = modNode.Context.DocumentTreeView.Create(options.CreateTypeDef(modNode.Document.ModuleDef));
		}
Exemplo n.º 10
0
        CreateNestedTypeDefCommand(TypeTreeNode ownerType, TypeDefOptions options)
        {
            this.ownerType = ownerType;

            var modNode = ILSpyTreeNode.GetNode<AssemblyTreeNode>(ownerType);
            Debug.Assert(modNode != null);
            if (modNode == null)
                throw new InvalidOperationException();
            this.nestedType = new TypeTreeNode(options.CreateTypeDef(modNode.LoadedAssembly.ModuleDefinition), modNode.Parent as AssemblyTreeNode ?? modNode);
        }
Exemplo n.º 11
0
        public TypeOptionsVM(TypeDefOptions 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;
            }
            this.TypeSigCreator = new TypeSigCreatorVM(typeSigCreatorOptions);
            this.TypeSigCreator.PropertyChanged += typeSigCreator_PropertyChanged;

            this.CustomAttributesVM = new CustomAttributesVM(ownerModule, decompilerService, ownerType, null);
            this.DeclSecuritiesVM   = new DeclSecuritiesVM(ownerModule, decompilerService, ownerType, null);
            this.GenericParamsVM    = new GenericParamsVM(ownerModule, decompilerService, ownerType, null);
            this.InterfaceImplsVM   = new TypeDefOrRefAndCAsVM <InterfaceImpl>(dnSpy_AsmEditor_Resources.EditInterfaceImpl, dnSpy_AsmEditor_Resources.CreateInterfaceImpl, ownerModule, decompilerService, ownerType, null);

            this.origOptions   = options;
            this.IsNestedType  = (options.Attributes & TypeAttributes.VisibilityMask) > TypeAttributes.Public;
            this.TypeKind      = new EnumListVM(typeKindList, (a, b) => OnTypeKindChanged());
            this.TypeLayout    = new EnumListVM(typeLayoutList, (a, b) => InitializeTypeKind());
            this.TypeSemantics = new EnumListVM(typeSemanticsList, (a, b) => InitializeTypeKind());
            this.PackingSize   = new NullableUInt16VM(a => HasErrorUpdated());
            this.ClassSize     = new NullableUInt32VM(a => HasErrorUpdated());

            Types.TypeVisibility start, end;
            if (!IsNestedType)
            {
                start = Types.TypeVisibility.NotPublic;
                end   = Types.TypeVisibility.Public;
            }
            else
            {
                start = Types.TypeVisibility.NestedPublic;
                end   = Types.TypeVisibility.NestedFamORAssem;
            }
            for (var t = Types.TypeVisibility.NotPublic; t <= Types.TypeVisibility.NestedFamORAssem; t++)
            {
                if (t < start || t > end)
                {
                    TypeVisibility.Items.RemoveAt(TypeVisibility.GetIndex(t));
                }
            }

            InitializeTypeKind();
            this.TypeSigCreator.CanAddFnPtr = false;
            Reinitialize();
        }
Exemplo n.º 12
0
        CreateTypeDefCommand(IList <TypeDef> ownerList, ILSpyTreeNode ownerNode, TypeDefOptions options)
        {
            this.ownerList = ownerList;
            var modNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(ownerNode);

            Debug.Assert(modNode != null);
            if (modNode == null)
            {
                throw new InvalidOperationException();
            }
            this.nsNodeCreator = new NamespaceTreeNodeCreator(options.Namespace, modNode);
            this.typeNode      = new TypeTreeNode(options.CreateTypeDef(modNode.DnSpyFile.ModuleDef), modNode.Parent as AssemblyTreeNode ?? modNode);
        }
Exemplo n.º 13
0
        CreateNestedTypeDefCommand(TypeTreeNode ownerType, TypeDefOptions options)
        {
            this.ownerType = ownerType;

            var modNode = ILSpyTreeNode.GetNode <AssemblyTreeNode>(ownerType);

            Debug.Assert(modNode != null);
            if (modNode == null)
            {
                throw new InvalidOperationException();
            }
            this.nestedType = new TypeTreeNode(options.CreateTypeDef(modNode.DnSpyFile.ModuleDef), modNode.Parent as AssemblyTreeNode ?? modNode);
        }
Exemplo n.º 14
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();
            }
            var options = TypeDefOptions.Create(UTF8String.Empty, TypeConstants.DEFAULT_TYPE_NAME, module.CorLibTypes.Object.TypeDefOrRef, true);

            var data = new TypeOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, null);
            var win  = new TypeOptionsDlg();

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

            var cmd = new CreateNestedTypeDefCommand(typeNode, data.CreateTypeDefOptions());

            UndoCommandManager.Instance.Add(cmd);
            MainWindow.Instance.JumpToReference(cmd.nestedType);
        }
Exemplo n.º 15
0
 void InitializeFrom(TypeDefOptions options)
 {
     Attributes                    = options.Attributes;
     Namespace                     = options.Namespace;
     Name                          = options.Name;
     PackingSize.Value             = options.PackingSize;
     ClassSize.Value               = options.ClassSize;
     BaseTypeSig                   = options.BaseType.ToTypeSig();
     TypeVisibility.SelectedItem   = (Types.TypeVisibility)((int)(options.Attributes & TypeAttributes.VisibilityMask) >> 0);
     TypeLayout.SelectedItem       = (Types.TypeLayout)(((int)options.Attributes >> 3) & 3);
     TypeSemantics.SelectedItem    = (Types.TypeSemantics)(((int)options.Attributes >> 5) & 1);
     TypeStringFormat.SelectedItem = (Types.TypeStringFormat)(((int)options.Attributes >> 16) & 3);
     TypeCustomFormat.SelectedItem = (Types.TypeCustomFormat)(((int)options.Attributes >> 22) & 3);
     CustomAttributesVM.InitializeFrom(options.CustomAttributes);
     DeclSecuritiesVM.InitializeFrom(options.DeclSecurities);
     GenericParamsVM.InitializeFrom(options.GenericParameters);
     InterfaceImplsVM.InitializeFrom(options.Interfaces);
 }
Exemplo n.º 16
0
		TypeDefSettingsCommand(ModuleDef module, TypeTreeNode typeNode, TypeDefOptions options) {
			this.module = module;
			this.typeNode = typeNode;
			this.newOptions = options;
			this.origOptions = new TypeDefOptions(typeNode.TypeDefinition);

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

			this.nameChanged = origOptions.Name != newOptions.Name;
			if (this.origParentNode is NamespaceTreeNode) {
				var asmNode = (AssemblyTreeNode)this.origParentNode.Parent;
				if (!AssemblyTreeNode.NamespaceStringEqualsComparer.Equals(newOptions.Namespace, origOptions.Namespace))
					this.nsNodeCreator = new NamespaceTreeNodeCreator(newOptions.Namespace, asmNode);
			}

			if (this.nameChanged || origOptions.Namespace != newOptions.Namespace)
				this.typeRefInfos = RefFinder.FindTypeRefsToThisModule(module).Where(a => RefFinder.TypeEqualityComparerInstance.Equals(a, typeNode.TypeDefinition)).Select(a => new TypeRefInfo(a)).ToArray();
		}
Exemplo n.º 17
0
		CreateTypeDefCommand(IList<TypeDef> ownerList, ILSpyTreeNode ownerNode, TypeDefOptions options) {
			this.ownerList = ownerList;
			var modNode = ILSpyTreeNode.GetNode<AssemblyTreeNode>(ownerNode);
			Debug.Assert(modNode != null);
			if (modNode == null)
				throw new InvalidOperationException();
			this.nsNodeCreator = new NamespaceTreeNodeCreator(options.Namespace, modNode);
			this.typeNode = new TypeTreeNode(options.CreateTypeDef(modNode.LoadedAssembly.ModuleDefinition), modNode.Parent as AssemblyTreeNode ?? modNode);
		}
Exemplo n.º 18
0
		TypeDefOptions CopyTo(TypeDefOptions options) {
			options.Attributes = Attributes;
			options.Namespace = Namespace;
			options.Name = Name;
			options.PackingSize = PackingSize.Value;
			options.ClassSize = ClassSize.Value;
			options.BaseType = BaseTypeSig.ToTypeDefOrRef();
			options.CustomAttributes.Clear();
			options.CustomAttributes.AddRange(CustomAttributesVM.Collection.Select(a => a.CreateCustomAttributeOptions().Create()));
			options.DeclSecurities.Clear();
			options.DeclSecurities.AddRange(DeclSecuritiesVM.Collection.Select(a => a.CreateDeclSecurityOptions().Create(ownerModule)));
			options.GenericParameters.Clear();
			options.GenericParameters.AddRange(GenericParamsVM.Collection.Select(a => a.CreateGenericParamOptions().Create(ownerModule)));
			options.Interfaces.Clear();
			options.Interfaces.AddRange(InterfaceImplsVM.Collection.Select(a => a.CreateTypeDefOrRefAndCAOptions().CreateInterfaceImpl(ownerModule)));
			if (ModelUtils.GetHasSecurityBit(options.DeclSecurities, options.CustomAttributes))
				options.Attributes |= TypeAttributes.HasSecurity;
			else
				options.Attributes &= ~TypeAttributes.HasSecurity;
			return options;
		}
Exemplo n.º 19
0
		void InitializeFrom(TypeDefOptions options) {
			Attributes = options.Attributes;
			Namespace = options.Namespace;
			Name = options.Name;
			PackingSize.Value = options.PackingSize;
			ClassSize.Value = options.ClassSize;
			BaseTypeSig = options.BaseType.ToTypeSig();
			TypeVisibility.SelectedItem = (Types.TypeVisibility)((int)(options.Attributes & TypeAttributes.VisibilityMask) >> 0);
			TypeLayout.SelectedItem = (Types.TypeLayout)(((int)options.Attributes >> 3) & 3);
			TypeSemantics.SelectedItem = (Types.TypeSemantics)(((int)options.Attributes >> 5) & 1);
			TypeStringFormat.SelectedItem = (Types.TypeStringFormat)(((int)options.Attributes >> 16) & 3);
			TypeCustomFormat.SelectedItem = (Types.TypeCustomFormat)(((int)options.Attributes >> 22) & 3);
			CustomAttributesVM.InitializeFrom(options.CustomAttributes);
			DeclSecuritiesVM.InitializeFrom(options.DeclSecurities);
			GenericParamsVM.InitializeFrom(options.GenericParameters);
			InterfaceImplsVM.InitializeFrom(options.Interfaces);
		}
Exemplo n.º 20
0
		public TypeOptionsVM(TypeDefOptions 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, ownerType, null);
			DeclSecuritiesVM = new DeclSecuritiesVM(ownerModule, decompilerService, ownerType, null);
			GenericParamsVM = new GenericParamsVM(ownerModule, decompilerService, ownerType, null);
			InterfaceImplsVM = new TypeDefOrRefAndCAsVM<InterfaceImpl>(dnSpy_AsmEditor_Resources.EditInterfaceImpl, dnSpy_AsmEditor_Resources.CreateInterfaceImpl, ownerModule, decompilerService, ownerType, null);

			origOptions = options;
			IsNestedType = (options.Attributes & TypeAttributes.VisibilityMask) > TypeAttributes.Public;
			TypeKind = new EnumListVM(typeKindList, (a, b) => OnTypeKindChanged());
			TypeLayout = new EnumListVM(typeLayoutList, (a, b) => InitializeTypeKind());
			TypeSemantics = new EnumListVM(typeSemanticsList, (a, b) => InitializeTypeKind());
			PackingSize = new NullableUInt16VM(a => HasErrorUpdated());
			ClassSize = new NullableUInt32VM(a => HasErrorUpdated());

			Types.TypeVisibility start, end;
			if (!IsNestedType) {
				start = Types.TypeVisibility.NotPublic;
				end = Types.TypeVisibility.Public;
			}
			else {
				start = Types.TypeVisibility.NestedPublic;
				end = Types.TypeVisibility.NestedFamORAssem;
			}
			for (var t = Types.TypeVisibility.NotPublic; t <= Types.TypeVisibility.NestedFamORAssem; t++) {
				if (t < start || t > end)
					TypeVisibility.Items.RemoveAt(TypeVisibility.GetIndex(t));
			}

			InitializeTypeKind();
			TypeSigCreator.CanAddFnPtr = false;
			Reinitialize();
		}
Exemplo n.º 21
0
		public MergedImportedType(TypeDef targetType, MergeKind mergeKind) {
			TargetType = targetType;
			MergeKind = mergeKind;
			NewTypeDefOptions = new TypeDefOptions();
		}
Exemplo n.º 22
0
		CreateTypeDefCommand(IList<TypeDef> ownerList, IFileTreeNodeData ownerNode, TypeDefOptions options) {
			this.ownerList = ownerList;
			var modNode = ownerNode.GetModuleNode();
			Debug.Assert(modNode != null);
			if (modNode == null)
				throw new InvalidOperationException();
			this.nsNodeCreator = new NamespaceNodeCreator(options.Namespace, modNode);
			this.typeNode = modNode.Context.FileTreeView.Create(options.CreateTypeDef(modNode.DnSpyFile.ModuleDef));
		}
Exemplo n.º 23
0
		CreateNestedTypeDefCommand(ITypeNode ownerType, TypeDefOptions options) {
			this.ownerType = ownerType;

			var modNode = ownerType.GetModuleNode();
			Debug.Assert(modNode != null);
			if (modNode == null)
				throw new InvalidOperationException();
			this.nestedType = ownerType.Create(options.CreateTypeDef(modNode.DnSpyFile.ModuleDef));
		}
Exemplo n.º 24
0
		TypeDefSettingsCommand(ModuleDef module, ITypeNode typeNode, TypeDefOptions options) {
			this.module = module;
			this.typeNode = typeNode;
			this.newOptions = options;
			this.origOptions = new TypeDefOptions(typeNode.TypeDef);

			this.origParentNode = (IFileTreeNodeData)typeNode.TreeNode.Parent.Data;
			this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(typeNode.TreeNode);
			Debug.Assert(this.origParentChildIndex >= 0);
			if (this.origParentChildIndex < 0)
				throw new InvalidOperationException();

			this.nameChanged = origOptions.Name != newOptions.Name;
			if (this.origParentNode is INamespaceNode) {
				var modNode = (IModuleFileNode)this.origParentNode.TreeNode.Parent.Data;
				if (newOptions.Namespace != origOptions.Namespace)
					this.nsNodeCreator = new NamespaceNodeCreator(newOptions.Namespace, modNode);
			}

			if (this.nameChanged || origOptions.Namespace != newOptions.Namespace)
				this.typeRefInfos = RefFinder.FindTypeRefsToThisModule(module).Where(a => RefFinder.TypeEqualityComparerInstance.Equals(a, typeNode.TypeDef)).Select(a => new TypeRefInfo(a)).ToArray();
		}