本文整理汇总了C#中Compiler.Run方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.Run方法的具体用法?C# Compiler.Run怎么用?C# Compiler.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compiler
的用法示例。
在下文中一共展示了Compiler.Run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
public virtual int Generate(string inputFilePath, string inputFileContents, string defaultNamespace, IntPtr[] outputFileContents, out uint outputSize, IVsGeneratorProgress progressCallback)
{
string inputFolder = Path.GetDirectoryName(inputFilePath);
string oldCurDir = Environment.CurrentDirectory;
try {
Environment.CurrentDirectory = inputFolder; // --macros should be relative to file being processed
var sourceFile = new StringCharSourceFile(inputFileContents, inputFilePath);
var sink = ToMessageSink(progressCallback);
var c = new Compiler(sink, sourceFile);
var options = new BMultiMap<string, string>();
var argList = G.SplitCommandLineArguments(defaultNamespace);
UG.ProcessCommandLineArguments(argList, options, "", LEL.Compiler.ShortOptions, LEL.Compiler.TwoArgOptions);
string _;
var KnownOptions = LEL.Compiler.KnownOptions;
if (options.TryGetValue("help", out _) || options.TryGetValue("?", out _))
LEL.Compiler.ShowHelp(KnownOptions);
Symbol minSeverity = MessageSink.Note;
var filter = new SeverityMessageFilter(MessageSink.Console, minSeverity);
if (LEL.Compiler.ProcessArguments(c, options)) {
LEL.Compiler.WarnAboutUnknownOptions(options, MessageSink.Console, KnownOptions);
if (c != null)
{
c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("LEL.Prelude"));
c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("Loyc.LLParserGenerator"));
c.AddMacros(typeof(Loyc.LLParserGenerator.Macros).Assembly);
c.Run();
}
var outputBytes = Encoding.UTF8.GetBytes(c.Output.ToString());
c.Output = null; // no longer needed
outputSize = (uint)outputBytes.Length;
outputFileContents[0] = Marshal.AllocCoTaskMem(outputBytes.Length);
Marshal.Copy(outputBytes, 0, outputFileContents[0], outputBytes.Length);
}
else
{
outputFileContents[0] = IntPtr.Zero;
outputSize = 0;
}
return VSConstants.S_OK;
} finally {
Environment.CurrentDirectory = oldCurDir;
}
}
示例2: Main
/// <summary>
/// Main entry point for the compiler.
/// </summary>
/// <param name="args">The command line arguments.</param>
internal static void Main(string[] args)
{
Compiler compiler = new Compiler();
compiler.Run(args);
}