public NamespaceNodeCreator(string ns, ModuleDocumentNode modNode) {
			this.modNode = modNode;
			nsNode = modNode.FindNode(ns);
			if (nsNode == null) {
				nsNode = modNode.Create(ns);
				nsNodeCreated = true;
			}
		}
Beispiel #2
0
		RenameNamespaceCommand(string newName, NamespaceNode nsNode) {
			this.newName = newName;
			origName = nsNode.Name;
			this.nsNode = nsNode;
			existingNsNode = (NamespaceNode)nsNode.TreeNode.Parent.DataChildren.FirstOrDefault(a => a is NamespaceNode && newName == ((NamespaceNode)a).Name);

			var module = nsNode.GetModule();
			Debug.Assert(module != null);
			if (module == null)
				throw new InvalidOperationException();

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

			// Make sure the exact same namespace names are restored if we undo. The names are UTF8
			// strings, but not necessarily canonicalized if it's an obfuscated assembly.
			nsNode.TreeNode.EnsureChildrenLoaded();
			origChildren = nsNode.TreeNode.DataChildren.Cast<TypeNode>().ToArray();
			typeNamespaces = new UTF8String[nsNode.TreeNode.Children.Count];
			for (int i = 0; i < typeNamespaces.Length; i++)
				typeNamespaces[i] = origChildren[i].TypeDef.Namespace;

			typeRefInfos = GetTypeRefInfos(module, new[] { nsNode });
		}
Beispiel #3
0
		DeleteNamespaceCommand(NamespaceNode[] nodes) {
			parents = nodes.Select(a => (DocumentTreeNodeData)a.TreeNode.Parent.Data).ToArray();
			this.nodes = new DeletableNodes<NamespaceNode>(nodes);
			modelNodes = new DeleteModelNodes();
		}
Beispiel #4
0
			public void Restore(NamespaceNode[] nodes, DocumentTreeNodeData[] parents) {
				Debug.Assert(infos != null);
				if (infos == null)
					throw new InvalidOperationException();
				Debug.Assert(infos.Length == nodes.Length);
				if (infos.Length != nodes.Length)
					throw new InvalidOperationException();

				for (int i = infos.Length - 1; i >= 0; i--) {
					var info = infos[i];

					for (int j = info.Types.Length - 1; j >= 0; j--)
						info.Module.Types.Insert(info.Indexes[j], info.Types[j]);
				}

				infos = null;
			}
Beispiel #5
0
			public void Delete(NamespaceNode[] nodes, DocumentTreeNodeData[] parents) {
				Debug.Assert(parents != null && nodes.Length == parents.Length);
				Debug.Assert(infos == null);
				if (infos != null)
					throw new InvalidOperationException();

				infos = new ModuleInfo[nodes.Length];

				for (int i = 0; i < infos.Length; i++) {
					var node = nodes[i];
					var module = parents[i].GetModule();
					Debug.Assert(module != null);
					if (module == null)
						throw new InvalidOperationException();

					var info = new ModuleInfo(module, node.TreeNode.Children.Count);
					infos[i] = info;

					for (int j = 0; j < node.TreeNode.Children.Count; j++) {
						var typeNode = (TypeNode)node.TreeNode.Children[j].Data;
						int index = module.Types.IndexOf(typeNode.TypeDef);
						Debug.Assert(index >= 0);
						if (index < 0)
							throw new InvalidOperationException();
						module.Types.RemoveAt(index);
						info.Types[j] = typeNode.TypeDef;
						info.Indexes[j] = index;
					}
				}
			}
Beispiel #6
0
		void Decompile(NamespaceNode node) {
			var children = GetChildren(node).OfType<TypeNode>().Select(a => a.TypeDef).ToArray();
			decompiler.DecompileNamespace(node.Name, children, output, decompilationContext);
		}