public virtual NamespaceGraph GetNamespace(String path) { if (path.Length == 0) { return(this); } int index = path.IndexOf("::"); if (index == -1) { return(namespaces[path] as NamespaceGraph); } else { String partial = path.Substring(0, index); NamespaceGraph ng = namespaces[partial] as NamespaceGraph; if (ng == null) { // ng = AddNamespace(new NamespaceGraph(partial)); // throw new ArgumentException("Namespace part " + partial + " wasn't found for " + path); return(null); } return(ng.GetNamespace(path.Substring(index + 2))); } }
protected NamespaceGraph GetOrCreateNamespace(String namespaceName) { NamespaceGraph ng = namespaces[namespaceName] as NamespaceGraph; if (ng != null) { return(ng); } if (namespaceName.IndexOf('.') == -1) { return(AddNamespace(new NamespaceGraph(namespaceName))); } String[] parts = namespaceName.Split('.'); foreach (String ns in parts) { if (ng != null) { ng = ng.GetOrCreateNamespace(ns); } else { ng = GetOrCreateNamespace(ns); } } return(ng); }
public NamespaceGraph AddNamespace(NamespaceGraph graph) { if (namespaces.Contains(graph.name)) { throw new ArgumentNullException("Namespace " + graph.name + " already exists."); } namespaces[graph.name] = graph; return(graph); }
public override NamespaceGraph GetNamespace(String path) { NamespaceGraph ng = base.GetNamespace(path); if (ng == null && parent != null) { ng = parent.GetNamespace(path); } return(ng); }
public NamespaceGraph DefineNamespace(String namespaceName) { if (parent == null) { return(GetOrCreateNamespace(namespaceName.Replace("::", "."))); } else { definedNamespace = parent.DefineNamespace(namespaceName); return(definedNamespace); } }
public virtual TypeDefinition GetType(String path) { int index = path.LastIndexOf("::"); if (index == -1) { return(types[path] as TypeDefinition); } String ns = path.Substring(0, index); NamespaceGraph ng = GetNamespace(ns); if (ng == null) { // throw new ArgumentException("Namespace "+ ns + " could not be found"); return(null); } return(ng.GetType(path.Substring(index + 2))); }
/// <summary> /// Make the types and subnamespaces available on the /// root of this space. /// </summary> /// <param name="namespaceName"></param> public void AddRequire(String namespaceName) { if (parent == null) { throw new ApplicationException("You can't use require on a root type space view - this is a compiler error"); } NamespaceGraph ng = parent.GetNamespace(namespaceName); if (ng == null) { throw new ArgumentException("Could not find namespace " + namespaceName + ". Aren't you forgetting to reference some assembly?"); } foreach (NamespaceGraph sub in ng.Namespaces) { if (namespaces.Contains(sub.Name)) { RegisterAmbiguity(sub); continue; } namespaces.Add(sub.Name, sub); } foreach (TypeDefinition type in ng.Types.Values) { if (types.Contains(type.Name)) { RegisterAmbiguity(type); continue; } types[type.Name] = type; } }
private void RegisterAmbiguity(NamespaceGraph ns) { ambiguities.Add(ns.Name, ns); }
private void AddType(Type type) { NamespaceGraph ng = GetOrCreateNamespace(type.Namespace); ng.AddExternalType(type); }