/// <summary> /// Merges given node into this node. Removes the child nodes from the other node. /// </summary> public void Merge(RNamespaceTreeNode other) { ContractUtils.Requires(other != null); if (other._typeDefs != null) { _typeDefs.AddRange(other._typeDefs); other._typeDefs = null; } if (other._firstChild != null) { ContractUtils.Assert(other._lastChild != null); if (_firstChild == null) { // this namespace has no subnamespaces: _firstChild = other._firstChild; _lastChild = other._lastChild; } else { // concat the lists: _lastChild._nextSibling = other._firstChild; _lastChild = other._lastChild; } other._firstChild = other._lastChild = null; } }
public void Add(Module module) { ContractUtils.Requires(module != null); Type[] types; try { types = module.GetTypes(); } catch (Exception) { Console.WriteLine(module.Assembly.Location); return; } foreach (Type type in types) { if (type.Attributes.IsNested()) { continue; } string prefix = type.Namespace ?? ""; RNamespaceTreeNode ns = null; while (true) { RNamespaceTreeNode existing; if (_names.TryGetValue(prefix, out existing)) { if (ns == null) { existing.AddType(type); } else { existing.AddNamespace(ns); } break; } ContractUtils.Assert(prefix.Length > 0); int lastDot = prefix.LastIndexOf('.', prefix.Length - 1, prefix.Length); string name = (lastDot >= 0) ? prefix.Substring(lastDot + 1) : prefix; RNamespaceTreeNode newNs = new RNamespaceTreeNode(name); if (ns == null) { newNs.AddType(type); } else { newNs.AddNamespace(ns); } ns = newNs; _names.Add(prefix, ns); prefix = (lastDot >= 0) ? prefix.Substring(0, lastDot) : ""; } } }
public IEnumerable <RNamespaceTreeNode> GetNamespaces() { RNamespaceTreeNode current = _firstChild; while (current != null) { yield return(current); current = current._nextSibling; } }
internal void AddNamespace(RNamespaceTreeNode ns) { ContractUtils.Assert(ns != null && ns._nextSibling == null); ContractUtils.Assert((_firstChild == null) == (_lastChild == null)); if (_firstChild == null) { // our first child: _firstChild = _lastChild = ns; } else { // add to the end of the children linked list: _lastChild._nextSibling = ns; _lastChild = ns; } }
public RNamespaceTree() { _names = new Dictionary<string, RNamespaceTreeNode>(); _names.Add("", _root = new RNamespaceTreeNode("")); }
public RNamespaceTree() { _names = new Dictionary <string, RNamespaceTreeNode>(); _names.Add("", _root = new RNamespaceTreeNode("")); }