Пример #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);
        }
Пример #2
0
        public CompilerResults CompileAssemblyFromFileBatch(CompilerParameters options, string[] fileNames)
        {
            //System.Diagnostics.Debug.Assert(false);
            foreach (string file in fileNames)
            {
                if (file.ToLower().EndsWith(".xaml"))
                {
                    return(CompileAssemblyFromFileBatchImpl(options, fileNames));
                }
            }

            if (options.ToString() == "" || options == null)
            {
                return(new CSharpCodeProvider().CreateCompiler().CompileAssemblyFromFileBatch(options, fileNames));
            }
            else
            {
                return(new CSharpCodeProvider(new Dictionary <string, string>()
                {
                    { "CompilerVersion", options.ToString() }
                }).CreateCompiler().CompileAssemblyFromFileBatch(options, fileNames));
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a <see cref="CompilationException"/> including details of test compilation failure
        /// </summary>
        /// <param name="compiler">The <see cref="System.CodeDom.Compiler.ICodeCompiler"/> being used in the compilation</param>
        /// <param name="parameters">The <see cref="System.CodeDom.Compiler.CompilerParameters"/> that were sent to the <paramref name="compiler"/></param>
        /// <param name="results">The <see cref="System.CodeDom.Compiler.CompilerResults"/> sent back from the compiler</param>
        /// <param name="sources">An array of source (code) being compiled</param>
        public CompilationException(
            ICodeCompiler compiler,
            CompilerParameters parameters,
            CompilerResults results,
            params String[] sources
            )
        {
            StringWriter sw = new StringWriter();

            sw.WriteLine("Compilation:  {0} errors", results.Errors.Count);
            sw.WriteLine("Compiler: {0}", compiler.GetType().Name);
            sw.WriteLine("CompilerParameters: {0}", parameters.ToString());
            foreach (CompilerError error in results.Errors)
            {
                sw.WriteLine(error.ToString());
            }
            sw.WriteLine("Sources:");
            foreach (string source in sources)
            {
                sw.WriteLine(source);
            }

            this.message = sw.ToString();
        }
Пример #4
0
        public CompilationException(
            CodeDomProvider provider,
            CompilerParameters parameters,
            CompilerResults results,
            params String[] sources
            )
        {
            StringWriter sw = new StringWriter();

            sw.WriteLine("Compilation:  {0} errors", results.Errors.Count);
            sw.WriteLine("Compiler: {0}", provider.FileExtension);
            sw.WriteLine("CompilerParameters: {0}", parameters.ToString());
            foreach (CompilerError error in results.Errors)
            {
                sw.WriteLine(error.ToString());
            }
            sw.WriteLine("Sources:");
            foreach (string source in sources)
            {
                sw.WriteLine(source);
            }

            this.body = sw.ToString();
        }