本文整理汇总了C#中Host.CompileLinqQuery方法的典型用法代码示例。如果您正苦于以下问题:C# Host.CompileLinqQuery方法的具体用法?C# Host.CompileLinqQuery怎么用?C# Host.CompileLinqQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Host
的用法示例。
在下文中一共展示了Host.CompileLinqQuery方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
public ActionResult Index(LINQPadViewModel model, HttpPostedFileBase fileUpload)
{
Host host = new Host();
if (model.References == null)
{
model.References = string.Empty;
}
if (model.Namespaces == null)
{
model.Namespaces = string.Empty;
}
Query query;
if (fileUpload != null)
{
query = host.ParseLinqFile(new StreamReader(fileUpload.InputStream));
ModelState.Clear();
if (query.Reference != null)
model.References = string.Join(Environment.NewLine, query.Reference);
if (query.Namespace != null)
model.Namespaces = string.Join(Environment.NewLine, query.Namespace);
model.Kind = (KindEnum)Enum.Parse(typeof(KindEnum), query.Kind);
model.Code = query.Code;
}
else
{
query = new Query
{
Kind = model.Kind.ToString(),
Reference = model.References.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries),
Namespace = model.Namespaces.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries),
Code = model.Code
};
}
CompilerResults cr = host.CompileLinqQuery(query);
if (cr.Errors != null && cr.Errors.Count > 0)
{
foreach(CompilerError ce in cr.Errors)
{
model.Results += ce + "\r\n";
}
}
else
{
StringWriter sw = new StringWriter();
host.Run<IndentTextSerializer>(cr, sw);
model.Results = sw.ToString();
}
return View(model);
}