APISampleUnitTestsCS.FAQ.Execute C# (CSharp) Метод

Execute() публичный Метод

public Execute ( Compilation comp ) : string
comp Compilation
Результат string
        public string Execute(Compilation comp)
        {
            var output = new StringBuilder();
            string exeFilename = "Output.exe", outputName = null, pdbFilename = "Output.pdb", xmlCommentsFilename = "Output.xml";
            EmitResult emitResult = null;

            using (var ilStream = new FileStream(exeFilename, FileMode.OpenOrCreate))
                using (var pdbStream = new FileStream(pdbFilename, FileMode.OpenOrCreate))
                    using (var xmlCommentsStream = new FileStream(xmlCommentsFilename, FileMode.OpenOrCreate))
                    {
                        // Emit IL, PDB and xml documentation comments for the compilation to disk.
                        emitResult = comp.Emit(ilStream, outputName, pdbFilename, pdbStream, xmlCommentsStream);
                    }

            if (emitResult.Success)
            {
                var p = Process.Start(
                    new ProcessStartInfo()
                    {
                        FileName = exeFilename,
                        UseShellExecute = false,
                        RedirectStandardOutput = true
                    });
                output.Append(p.StandardOutput.ReadToEnd());
                p.WaitForExit();
            }
            else
            {
                output.AppendLine("Errors:");
                foreach (var diag in emitResult.Diagnostics)
                {
                    output.AppendLine(diag.ToString());
                }
            }

            return output.ToString();
        }