Compile() public static method

Compiles C# source code.
public static Compile ( string source, bool targetCSharp6 = false ) : CompilerResults
source string The source.
targetCSharp6 bool
return System.CodeDom.Compiler.CompilerResults
Example #1
0
        private static bool Compile(string tempFile)
        {
            var results = CSharpTestFile.Compile(File.ReadAllText(tempFile), true);

            if (results.Errors.Count > 0)
            {
                CompilerError error = null;

                error = TestUtilities.GetCompilerError(results);

                if (error != null)
                {
                    string messageFormat =
                        "Test source code should not produce compiler errors. " +
                        "Error: {0} - {1}, line {2}, column {3} ";
                    Assert.Fail(
                        messageFormat,
                        error.ErrorText,
                        tempFile,
                        error.Line,
                        error.Column);
                }
                return(false);
            }
            return(true);
        }
Example #2
0
 /// <summary>
 /// Compiles source code text to the specified assembly.
 /// </summary>
 /// <param name="text">Text to compile.</param>
 /// <param name="assemblyName">Output assembly name.</param>
 /// <returns>Compiler results.</returns>
 protected override CompilerResults Compile(string text, string assemblyName)
 {
     return(CSharpTestFile.Compile(text, assemblyName));
 }