本文整理汇总了C#中CompilerOptions.AddSourceItems方法的典型用法代码示例。如果您正苦于以下问题:C# CompilerOptions.AddSourceItems方法的具体用法?C# CompilerOptions.AddSourceItems怎么用?C# CompilerOptions.AddSourceItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CompilerOptions
的用法示例。
在下文中一共展示了CompilerOptions.AddSourceItems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetParser
private Parser GetParser()
{
if (_parser == null)
{
using (var options = new CompilerOptions())
{
var sourceItems = new SourceItem[]{
new TextItem()
{
Name = "GdlGrammer", ContentType = TextItemType.MGrammar, Reader = new StringReader(Language)
}
};
options.AddSourceItems(sourceItems);
CompilationResults results = Compiler.Compile(options);
if (results.HasErrors)
{
//TODO: show meaningful error message
throw new Exception("Failed to compile GDL ....");
}
else
{
foreach (var parserFactory in results.ParserFactories)
{
//TODO: Why inside foreach loop!!!
_parser = parserFactory.Value.Create();
}
}
}
}
return _parser;
}
示例2: GetParser
internal static Parser GetParser()
{
using (var options = new CompilerOptions())
{
var sourceItems = new SourceItem[]{
new TextItem()
{
Name = "GdlGrammar", ContentType = TextItemType.MGrammar, Reader = new StringReader(GDL)
}
};
options.AddSourceItems(sourceItems);
CompilationResults results = null;
results = Compiler.Compile(options);
if (results.HasErrors)
{
throw new Exception("Failed to compile GDL ...."
+ Environment.NewLine
+ results.Errors[0]);
}
else
{
foreach (var parserFactory in results.ParserFactories)
{
return parserFactory.Value.Create();
}
}
}
return null;
}