Пример #1
0
		RenameNamespaceCommand(string newName, NamespaceTreeNode nsNode) {
			this.newName = newName;
			this.origName = nsNode.Name;
			this.nsNode = nsNode;
			this.existingNsNode = (NamespaceTreeNode)nsNode.Parent.Children.FirstOrDefault(a => a is NamespaceTreeNode && AssemblyTreeNode.NamespaceStringEqualsComparer.Equals(newName, ((NamespaceTreeNode)a).Name));

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

			this.origParentNode = (ILSpyTreeNode)nsNode.Parent;
			this.origParentChildIndex = this.origParentNode.Children.IndexOf(nsNode);
			Debug.Assert(this.origParentChildIndex >= 0);
			if (this.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.EnsureChildrenFiltered();
			this.origChildren = nsNode.Children.Cast<TypeTreeNode>().ToArray();
			this.typeNamespaces = new UTF8String[nsNode.Children.Count];
			for (int i = 0; i < this.typeNamespaces.Length; i++)
				this.typeNamespaces[i] = origChildren[i].TypeDefinition.Namespace;

			this.typeRefInfos = GetTypeRefInfos(module, new[] { nsNode });
		}