CSScriptCompilers.CCSharpParser.ToTempFile C# (CSharp) Méthode

ToTempFile() public méthode

public ToTempFile ( bool imported ) : string
imported bool
Résultat string
        public string ToTempFile(bool imported)
        {
            if (!isClassless)
                throw new Exception("ClasslessCSharpParser.ToTempFile should not be called for standard C# code");

            string file = Path.GetTempFileName();

            if (File.Exists(file))
                File.Delete(file);

            string dir = Path.Combine(Path.GetTempPath(), "CSSCRIPT\\Classless");
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            file = Path.Combine(dir, Path.GetFileNameWithoutExtension(file) + ".cs");

            using (StreamWriter sw = new StreamWriter(file))
                sw.Write(imported ? CSharpCode : CSharpScriptCode);

            return file;
        }

Usage Example

Exemple #1
0
        public CompilerResults CompileAssemblyFromFileBatch(CompilerParameters options, string[] fileNames)
        {
            string        tempFile;
            ArrayList     classlessFiles = new ArrayList();
            ArrayList     files          = new ArrayList();
            int           count          = 0;
            CCSharpParser ccs;

            foreach (string file in fileNames)
            {
                ccs = new CCSharpParser(file);
                if (!ccs.isClassless)
                {
                    files.Add(file);
                }
                else
                {
                    tempFile = ccs.ToTempFile(count > 0);
                    classlessFiles.Add(tempFile);
                    files.Add(tempFile);
                }
                count++;
            }

            Microsoft.CSharp.CSharpCodeProvider provider;

            if (options.ToString() == "" || options == null)
            {
                return(new Microsoft.CSharp.CSharpCodeProvider().CreateCompiler().CompileAssemblyFromFileBatch(options, fileNames));
            }
            else
            {
                return(new Microsoft.CSharp.CSharpCodeProvider(new Dictionary <string, string>()
                {
                    { "CompilerVersion", options.ToString() }
                }).CreateCompiler().CompileAssemblyFromFileBatch(options, fileNames));
            }

            CompilerResults retval;

            retval = provider.CreateCompiler().CompileAssemblyFromFileBatch(options, (string[])files.ToArray(typeof(string)));


            if (!retval.Errors.HasErrors)
            {
                foreach (string file in classlessFiles)
                {
                    try
                    {
                        File.Delete(file);
                    }
                    catch {}
                }
            }

            return(retval);
        }
All Usage Examples Of CSScriptCompilers.CCSharpParser::ToTempFile