ReflectedNamespace GetReflectedNamespace(string namespaceFullName, Dictionary <string, ReflectedNamespace> namespaceFullNameMap) { ReflectedNamespace ns; if (namespaceFullNameMap.TryGetValue(namespaceFullName, out ns)) { return(ns); } string parentScopeName; string name = GetNameParts(namespaceFullName, out parentScopeName); ReflectedNamespace parent = null; if (parentScopeName != null) { // This can recursively create namespace objects for the entire chain as reqired parent = GetReflectedNamespace(parentScopeName, namespaceFullNameMap); } // Create a new namespace, and update the parent to point to it ns = new ReflectedNamespace(parent, assembly, name); if (parent != null) { parent.rawTypeMap[name] = ns; } else { rawTypeMap[name] = ns; } namespaceFullNameMap[namespaceFullName] = ns; return(ns); }
internal ReflectedAssembly(Assembly assem) { assembly = assem; Dictionary <string, ReflectedNamespace> namespaceFullNameMap = new Dictionary <string, ReflectedNamespace>(); Type[] types = assem.GetTypes(); // Walk all the types to discover all the namespaces foreach (Type type in types) { string typeFullName = type.FullName; // Nested types are named as "outerType+innerType". However, '+' cannot be used in a name. typeFullName = typeFullName.Replace('+', '_'); string parentScopeName; string name = GetNameParts(typeFullName, out parentScopeName); if (parentScopeName == null) { // This is global type. Add it to the assembly itself rawTypeMap[typeFullName] = type; } else { // Add the type to the containing namespace object ReflectedNamespace ns = GetReflectedNamespace(parentScopeName, namespaceFullNameMap); ns.rawTypeMap[name] = type; } } }
void GetName(StringBuilder sb, ReflectedNamespace ns) { if (ns.parent != null) { GetName(sb, ns.parent); sb.Append('.'); } sb.Append(ns.myNamespace); }
public ReflectedNamespace(ReflectedNamespace parentNamespace, Assembly fromAssembly, string nameSpace) { myNamespace = nameSpace; assembly = fromAssembly; parent = parentNamespace; }