コード例 #1
0
        public static IEnumerable <NsTreeItem> ToNsTree(this IEnumerable <LanguageSetting> settings)
        {
            var namespaces = settings.Select(o => o.Namespace.Split('.')[0]).Distinct().OrderBy(o => o).ToList();
            var root       = new NsTreeItem()
            {
                Name = "root"
            };

            foreach (var ns in namespaces)
            {
                settings.ProcessNs(root, ns);
            }

            var nodes = new List <NsTreeItem>();

            foreach (NsTreeItem node in root.Items)
            {
                nodes.Add(node);
                node.Parent = null;
            }
            root.Clear();


            return(nodes);
        }
コード例 #2
0
        public static void ProcessNs(this IEnumerable <LanguageSetting> allSettings, NsTreeItem node, string ns, int depth = 1, int customDepth = 0)
        {
            if (customDepth == 0)
            {
                customDepth = 1;
            }

            var thisNode = new NsTreeItem()
            {
                Parent = node, Name = (ns.Split('.').Last()), Namespace = ns, ImagePath = "Assets/Images/ns.png"
            };

            if (node == null)
            {
                node = thisNode;
            }
            else
            {
                node.AddChild(thisNode);
            }

            var namespaces = allSettings.Where(o => o.Namespace.StartsWith(ns + ".")).Select(o => o.Namespace.Substring(ns.Length + 1).Split('.')[0]).Distinct().OrderBy(o => o).ToList();

            if (!namespaces.Any())
            {
                thisNode.ImagePath = "Assets/Images/translation.png";
                thisNode.Settings  = allSettings.Where(o => o.Namespace == thisNode.Namespace);
                return;
            }

            var applicableSettings = allSettings.Where(o => o.Namespace.StartsWith(ns + ".")).ToList();

            if (depth > customDepth)
            {
                thisNode.HeldSetttings = applicableSettings;
                return;
            }

            depth++;
            foreach (var nextNs in namespaces)
            {
                applicableSettings.ProcessNs(thisNode, $"{ns}.{nextNs}", depth);
            }

            thisNode.IsLoaded = true;
        }