Exemplo n.º 1
0
        public void Process()
        {
            List <ITypeDefinition> allTypesToExport = GetAllTypesToExport();

            var byFile = allTypesToExport.GroupBy(ce => Compiler.PathMerger.ConvertRelativePath(Sk.GetExportPath(ce))).ToDictionary();

            byFile.ForEach(t => SortByNativeInheritance(t.Value));
            foreach (var f in byFile)
            {
                var customOrder = f.Value.Where(t => GetOrderInFile(t) != 0).ToList();
                if (customOrder.Count > 0)
                {
                    f.Value.RemoveAll(t => customOrder.Contains(t));
                    customOrder.Sort((x, y) => GetOrderInFile(x) - GetOrderInFile(y));
                    f.Value.InsertRange(0, customOrder.Where(t => GetOrderInFile(t) < 0));
                    f.Value.AddRange(customOrder.Where(t => GetOrderInFile(t) > 0));
                }
            }
            //sort types by OrderInFile if needed:
            //byFile.Where(k => k.Value.Where(t => GetOrderInFile(t) != 0).FirstOrDefault() != null).ForEach(t => t.Value.Sort((x, y) => GetOrderInFile(x) - GetOrderInFile(y)));

            var byFile2 = new Dictionary <JsFile, List <ITypeDefinition> >();

            foreach (var pair in byFile)
            {
                var file = new JsFile {
                    Filename = pair.Key, Units = new List <JsUnit> {
                        new JsUnit {
                            Statements = new List <JsStatement>()
                        }
                    }
                };
                byFile2.Add(file, pair.Value);
            }
            if (BeforeExportTypes != null)
            {
                BeforeExportTypes(byFile2);
            }
            //export by filenames and order
            byFile2.ForEachParallel(ExportTypesInFile);

            JsFiles = byFile2.Keys.ToList();

            if (Sk.ExportTsHeaders(Compiler.Project.Compilation))
            {
                ExportTsHeaders(allTypesToExport);
            }
        }