Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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);
        }