示例#1
0
        public static CompileResult Compile(
            IEnumerable <string> filenames, string assemblyName, string compilerOptions = ""
            )
        {
            var extension = Path.GetExtension(filenames.First()).ToLower();
            Func <CodeDomProvider> provider = null;

            switch (extension)
            {
            case ".cs":
                provider = () => new CSharpCodeProvider(new Dictionary <string, string>()
                {
                    { "CompilerVersion", "v4.0" }
                });
                break;

            case ".vb":
                provider = () => new VBCodeProvider(new Dictionary <string, string>()
                {
                    { "CompilerVersion", "v4.0" }
                });
                break;

            case ".fs":
                provider = () => {
                    var result = new FSharpCodeProvider();
                    return(result);
                };
                break;

            case ".il":
                provider = () =>
                {
                    var result = new CILCodeProvider();
                    return(result);
                };
                break;

            case ".cpp":
                provider = () =>
                {
                    var result = new CPPCodeProvider();
                    return(result);
                };
                break;

            default:
                throw new NotImplementedException("Extension '" + extension + "' cannot be compiled for test cases");
            }

            return(Compile(
                       provider, filenames, assemblyName, compilerOptions
                       ));
        }
示例#2
0
        public void Compile(string filename)
        {
            var provider = new FSharpCodeProvider();
            var compileParams = new CompilerParameters(GacAssembliesToCompileAgainst);
            compileParams.GenerateExecutable = true;
            compileParams.GenerateInMemory = false;
            compileParams.OutputAssembly = filename;

            CompilerResults r = provider.CompileAssemblyFromSource(compileParams, this.Code);
            Errors = r.Errors.Cast<CompilerError>().ToArray();
            ProducedExecutable = Errors.Length == 0;
        }
示例#3
0
        public static CompileResult Compile (
            IEnumerable<string> filenames, string assemblyName, string compilerOptions = ""
        ) {
            var extension = Path.GetExtension(filenames.First()).ToLower();
            Func<CodeDomProvider> provider = null;

            switch (extension) {
                case ".cs":
                    provider = () => new CSharpCodeProvider(new Dictionary<string, string>() { 
                        { "CompilerVersion", "v4.0" } 
                    });
                    break;

                case ".vb":
                    provider = () => new VBCodeProvider(new Dictionary<string, string>() { 
                        { "CompilerVersion", "v4.0" } 
                    });
                    break;

                case ".fs":
                    provider = () => {
                        var result = new FSharpCodeProvider();
                        return result;
                    };
                    break;

                case ".il":
                    provider = () =>
                    {
                        var result = new CILCodeProvider();
                        return result;
                    };
                    break;

                case ".cpp":
                    provider = () =>
                    {
                        var result = new CPPCodeProvider();
                        return result;
                    };
                    break;
                default:
                    throw new NotImplementedException("Extension '" + extension + "' cannot be compiled for test cases");
            }

            return Compile(
                provider, filenames, assemblyName, compilerOptions
            );
        }