public static string CompileToCSharp(DisposableTempDirectory provider, string outputDirectory = null, string moduleName = "Xython", string target = "x86_64-apple-macosx10.9", IEnumerable <string> additionalTypeDatabases = null, bool separateProcess = false, UnicodeMapper unicodeMapper = null, int expectedErrorCount = -1)
        {
            NewClassCompiler ncc = DefaultCSharpCompiler(unicodeMapper);

            List <string> typeDatabases = Compiler.kTypeDatabases;

            if (additionalTypeDatabases != null)
            {
                typeDatabases.AddRange(additionalTypeDatabases);
            }

            ClassCompilerLocations classCompilerLocations = new ClassCompilerLocations(new List <string> {
                provider.DirectoryPath, Compiler.kSwiftRuntimeGlueDirectory
            },
                                                                                       new List <string> {
                provider.DirectoryPath, Compiler.kSwiftRuntimeGlueDirectory
            },
                                                                                       typeDatabases);
            ClassCompilerNames compilerNames = new ClassCompilerNames(moduleName, null);

            if (separateProcess)
            {
                var args = new StringBuilder();
                args.Append($"--debug ");
                args.Append($"{Path.Combine (Path.GetDirectoryName (ncc.GetType ().Assembly.Location), "tom-swifty.exe")} ");
                args.Append($"--swift-bin-path={StringUtils.Quote (Compiler.CompilerLocation.SwiftCompilerBin)} ");
                args.Append($"--swift-lib-path={StringUtils.Quote (Path.GetDirectoryName (Compiler.CompilerLocation.SwiftCompilerLib))} ");
                args.Append($"--retain-xml-reflection ");
                foreach (var db in typeDatabases)
                {
                    args.Append($"--type-database-path={StringUtils.Quote (db)} ");
                }
                args.Append($"--retain-swift-wrappers ");
                args.Append($"--wrapping-module-name={StringUtils.Quote (moduleName)}Wrapping ");
                foreach (var l in classCompilerLocations.LibraryDirectories)
                {
                    args.Append($"-L {StringUtils.Quote (l)} ");
                }
                foreach (var m in classCompilerLocations.ModuleDirectories)
                {
                    args.Append($"-M {StringUtils.Quote (m)} ");
                }
                args.Append($"-o {StringUtils.Quote (outputDirectory ?? provider.DirectoryPath)} ");
                args.Append($"--module-name={StringUtils.Quote (moduleName)} ");
                return(ExecAndCollect.Run("mono", args.ToString()));
            }
            else
            {
                ErrorHandling errors = ncc.CompileToCSharp(classCompilerLocations, compilerNames, new List <string> {
                    target
                }, outputDirectory ?? provider.DirectoryPath);
                CheckErrors(errors, expectedErrorCount);
                return(null);
            }
        }
        static void Compile(SwiftyOptions options, UnicodeMapper unicodeMapper, ErrorHandling errors)
        {
            try {
                using (DisposableTempDirectory temp = new DisposableTempDirectory(null, true)) {
                    SwiftCompilerLocation compilerLocation = new SwiftCompilerLocation(options.SwiftBinPath, options.SwiftLibPath);
                    ClassCompilerOptions  compilerOptions  = new ClassCompilerOptions(options.TargetPlatformIs64Bit, options.Verbose, options.RetainXmlReflection, options.RetainSwiftWrappingCode);
                    NewClassCompiler      classCompiler    = new NewClassCompiler(compilerLocation, compilerOptions, unicodeMapper);

                    ClassCompilerNames     compilerNames          = new ClassCompilerNames(options.ModuleName, options.WrappingModuleName);
                    ClassCompilerLocations classCompilerLocations = new ClassCompilerLocations(options.ModulePaths, options.DylibPaths, options.TypeDatabasePaths);
                    var compileErrors = classCompiler.CompileToCSharp(classCompilerLocations, compilerNames, options.Targets, options.OutputDirectory);
                    errors.Add(compileErrors);
                }
            } catch (Exception err) {
                errors.Add(err);
            }
        }