Example #1
0
		public TypeNodeCreator(ModuleDocumentNode modNode, List<TypeDef> types) {
			if (modNode == null)
				throw new ArgumentNullException(nameof(modNode));
			if (types == null)
				throw new ArgumentNullException(nameof(types));
			if (types.Count == 0)
				throw new ArgumentException();

			var ns = (types[0].Namespace ?? UTF8String.Empty).String;
			foreach (var t in types) {
				var tns = (t.Namespace ?? UTF8String.Empty).String;
				if (tns != ns)
					throw new ArgumentException();
				// Can't be a nested type, and can't be part of a module yet
				if (t.DeclaringType != null || t.Module != null)
					throw new ArgumentException();
			}
			ownerList = modNode.Document.ModuleDef.Types;
			nsNodeCreator = new NamespaceNodeCreator(ns, modNode);
			typeNodes = types.Select(a => modNode.Context.DocumentTreeView.Create(a)).ToArray();
		}
Example #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();
		}
Example #3
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));
		}