private static void LoadFromAssembly(AssemblyMappingConfiguration assembly)
 {
     var types = assembly.Types.Select(t => t.UnderlineType).OrderBy(t => t.Namespace).AsEnumerable();
     var ns = CreateNamespace(assembly.RootNamespace, types, assembly);
     if (ns != null)
         Namespaces.Add(ns);
 }
 public AssemblyMappingConfiguration MapAssembly(Assembly assembly, string rootNamespace)
 {
     var configuration = new AssemblyMappingConfiguration(Configuration, assembly, rootNamespace);
     assemblies.Add(rootNamespace, configuration);
     return configuration;
 }
        private static NamespaceMapping CreateNamespace(string ns, IEnumerable<Type> availableTypes, AssemblyMappingConfiguration assembly, IMappingElement parent = null)
        {
            var separator = new[] { TypeSeparator };
            const StringSplitOptions options = StringSplitOptions.RemoveEmptyEntries;

            var @namespace = new NamespaceMapping
                                 {
                                     ID = Guid.NewGuid().ToString("N"),
                                     Name = ns.Split(separator, options).LastOrDefault(),
                                     FullName = ns,
                                     Parent = parent,
                                     Visible = true
                                 };

            @namespace.Types = availableTypes
                .Where(t => t.Namespace == ns)
                .Select(t => CreateTypeMapping(t, @namespace, assembly.For(t)))
                .ToList();

            @namespace.Namespaces = availableTypes
                .Where(t => t.Namespace != null && t.Namespace != ns && t.Namespace.StartsWith(ns))
                .GroupBy(t => t.Namespace)
                .Select(g => g.Key.Replace(ns + TypeSeparator, string.Empty).Split(separator, options).FirstOrDefault())
                .Select(nm => CreateNamespace(string.Concat(ns, TypeSeparator, nm), availableTypes.Where(t => t.Namespace != ns), assembly, @namespace))
                .ToList();

            return @namespace;
        }
 public TypeMappingConfiguration(Type type, AssemblyMappingConfiguration assemblyMappingConfiguration)
 {
     UnderlineType = type;
     Assembly = assemblyMappingConfiguration;
 }