void ProcessFile(ScriptInfo fileInfo)
        {
            try
            {
                var fileComparer = new FileParserComparer();

                var importedFile = new FileParser(fileInfo.fileName, fileInfo.parseParams, false, true, this.SearchDirs, throwOnError); //do not parse it yet (the third param is false)

                if (fileParsers.BinarySearch(importedFile, fileComparer) < 0)
                {
                    if (File.Exists(importedFile.fileName))
                    {
                        importedFile.ProcessFile(); //parse now namespaces, ref. assemblies and scripts; also it will do namespace renaming

                        this.fileParsers.Add(importedFile);
                        this.fileParsers.Sort(fileComparer);

                        foreach (string namespaceName in importedFile.ReferencedNamespaces)
                        {
                            PushNamespace(namespaceName);
                        }

                        foreach (string asmName in importedFile.ReferencedAssemblies)
                        {
                            PushAssembly(asmName);
                        }

                        foreach (string packageName in importedFile.Packages)
                        {
                            PushPackage(packageName);
                        }

                        foreach (string file in importedFile.Precompilers)
                        {
                            PushPrecompiler(file);
                        }

                        foreach (ScriptInfo scriptFile in importedFile.ReferencedScripts)
                        {
                            ProcessFile(scriptFile);
                        }

                        foreach (string resFile in importedFile.ReferencedResources)
                        {
                            PushResource(resFile);
                        }

                        foreach (string file in importedFile.IgnoreNamespaces)
                        {
                            PushIgnoreNamespace(file);
                        }

                        List <string> dirs = new List <string>(this.SearchDirs);
                        foreach (string dir in importedFile.ExtraSearchDirs)
                        {
                            if (Path.IsPathRooted(dir))
                            {
                                dirs.Add(Path.GetFullPath(dir));
                            }
                            else
                            {
                                dirs.Add(Path.Combine(Path.GetDirectoryName(importedFile.fileName), dir));
                            }
                        }
                        this.SearchDirs = dirs.ToArray();
                    }
                    else
                    {
                        importedFile.fileNameImported = importedFile.fileName;
                        this.fileParsers.Add(importedFile);
                        this.fileParsers.Sort(fileComparer);
                    }
                }
            }
            catch (Exception e)
            {
                throw e.ToNewException(
                          fileInfo.parseParams.importingErrorMessage,
                          ExecuteOptions.options.reportDetailedErrorInfo); // encapsulate: ExecuteOptions.options.reportDetailedErrorInfo
            }
        }
        /// <summary>
        /// Processes the imported script. Processing involves lookup for 'static Main' and renaming it so it does not
        /// interfere with the 'static Main' of the primary script. After renaming is done the new content is saved in the
        /// CS-Script cache and the new file location is returned. The saved file can be used late as an "included script".
        /// This technique can be from 'precompiler' scripts.
        /// <para>If the script file does not require renaming (static Main is not present) the method returns the
        /// original script file location.</para>
        /// </summary>
        /// <param name="scriptFile">The script file.</param>
        /// <returns></returns>
        public static string ProcessImportedScript(string scriptFile)
        {
            var parser = new FileParser(scriptFile, new ParsingParams(), true, true, new string[0], true);

            return(parser.FileToCompile);
        }
        /// <summary>
        /// Initialization of ScriptParser instance
        /// </summary>
        /// <param name="fileName">Script file name</param>
        /// <param name="searchDirs">Extra ScriptLibrary directory(s) </param>
        void Init(string fileName, string[] searchDirs)
        {
            ScriptPath = fileName;

            //process main file
            FileParser mainFile = new FileParser(fileName, null, true, false, searchDirs, throwOnError);

            this.apartmentState = mainFile.ThreadingModel;

            foreach (string file in mainFile.Precompilers)
            {
                PushPrecompiler(file);
            }

            foreach (string namespaceName in mainFile.IgnoreNamespaces)
            {
                PushIgnoreNamespace(namespaceName);
            }

            foreach (string namespaceName in mainFile.ReferencedNamespaces)
            {
                PushNamespace(namespaceName);
            }

            foreach (string asmName in mainFile.ReferencedAssemblies)
            {
                PushAssembly(asmName);
            }

            foreach (string name in mainFile.Packages)
            {
                PushPackage(name);
            }

            foreach (string resFile in mainFile.ReferencedResources)
            {
                PushResource(resFile);
            }

            foreach (string opt in mainFile.CompilerOptions)
            {
                PushCompilerOptions(opt);
            }

            List <string> dirs = new List <string>();

            dirs.Add(Path.GetDirectoryName(mainFile.fileName));//note: mainFile.fileName is warrantied to be a full name but fileName is not
            if (searchDirs != null)
            {
                dirs.AddRange(searchDirs);
            }

            foreach (string dir in mainFile.ExtraSearchDirs)
            {
                if (Path.IsPathRooted(dir))
                {
                    dirs.Add(Path.GetFullPath(dir));
                }
                else
                {
                    dirs.Add(Path.Combine(Path.GetDirectoryName(mainFile.fileName), dir));
                }
            }

            this.SearchDirs = dirs.ToArray().RemovePathDuplicates();

            //process imported files if any
            foreach (ScriptInfo fileInfo in mainFile.ReferencedScripts)
            {
                ProcessFile(fileInfo);
            }

            //Main script file shall always be the first. Add it now as previously array was sorted a few times
            this.fileParsers.Insert(0, mainFile);
        }