Mono.CSharp.dll 中是否有任何问题或者我缺少某些内容
我已从 Miguel de Icaza 的网站。
我试图构建某些程序,但一切都失败了。我的是一个简单的控制台应用程序。
情况1:仅根据条件打印名称。它工作得很好
static void Main(string[] args)
{
Evaluator.Run("using System;");
Evaluator.Run("using System.Linq;");
Evaluator.Run("using System.Collections.Generic;");
string dynamicQuery = ReplaceQuotes("List<string> names = new List<string> {'name1','name2','some thing else} ;");
dynamicQuery += ReplaceQuotes("foreach(string name in names)");
dynamicQuery += ReplaceQuotes("if(name.Contains('name'))");
dynamicQuery += "Console.WriteLine(name);";
Evaluator.Run(dynamicQuery);
Console.ReadLine();
}
private static string ReplaceQuotes(string str)
{
return str.Replace("'", "\"");
}
}
案例 2:尝试使用 LINQ 进行相同操作失败
string dynamicQuery = ReplaceQuotes("List<string> names = new List<string> {'name1','name2','some thing else'} ;");
dynamicQuery += ReplaceQuotes("var result = from name in names where name.Contains('name') select name;");
dynamicQuery += ReplaceQuotes("foreach(string name in result) Console.WriteLine(name);");
运行时出错
{interactive}(1,109): error CS1935: An implementation of `Where' query expressio
n pattern could not be found. Are you missing `System.Linq' using directive or `
System.Core.dll' assembly reference?
{interactive}(1,149): error CS1579: foreach statement cannot operate on variable
s of type `object' because it does not contain a definition for `GetEnumerator'
or is not accessible
案例 3:尝试使用 Lambda 进行相同操作
string dynamicQuery = ReplaceQuotes("List<string> names = new List<string> {'name1','name2','some thing else'} ;");
dynamicQuery += ReplaceQuotes("names.Where(i => i.Contains('name')).ToList().ForEach(i => Console.WriteLine(i));");
这次错误是
{interactive}(1,83): error CS1061: Type `System.Collections.Generic.List<string>
' does not contain a definition for `Where' and no extension method `Where' of t
ype `System.Collections.Generic.List<string>' could be found (are you missing a
using directive or an assembly reference?)
我在其中搜索的上网发现人们要求包含 System.Core 并导入正确的命名空间。
我已经有了这些命名空间
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.CSharp;
那么什么,哪里,为什么错了?
谢谢
I have downloaded the demo-repl.zip file from Miguel de Icaza's web site.
I was trying to build certain programs but all is failing. Mine is a simple console application.
Case 1: Only Print the name based on condition. It works well
static void Main(string[] args)
{
Evaluator.Run("using System;");
Evaluator.Run("using System.Linq;");
Evaluator.Run("using System.Collections.Generic;");
string dynamicQuery = ReplaceQuotes("List<string> names = new List<string> {'name1','name2','some thing else} ;");
dynamicQuery += ReplaceQuotes("foreach(string name in names)");
dynamicQuery += ReplaceQuotes("if(name.Contains('name'))");
dynamicQuery += "Console.WriteLine(name);";
Evaluator.Run(dynamicQuery);
Console.ReadLine();
}
private static string ReplaceQuotes(string str)
{
return str.Replace("'", "\"");
}
}
Case 2: Trying the same with LINQ fails
string dynamicQuery = ReplaceQuotes("List<string> names = new List<string> {'name1','name2','some thing else'} ;");
dynamicQuery += ReplaceQuotes("var result = from name in names where name.Contains('name') select name;");
dynamicQuery += ReplaceQuotes("foreach(string name in result) Console.WriteLine(name);");
Error at runtime being
{interactive}(1,109): error CS1935: An implementation of `Where' query expressio
n pattern could not be found. Are you missing `System.Linq' using directive or `
System.Core.dll' assembly reference?
{interactive}(1,149): error CS1579: foreach statement cannot operate on variable
s of type `object' because it does not contain a definition for `GetEnumerator'
or is not accessible
Case 3: Trying the same with Lambda
string dynamicQuery = ReplaceQuotes("List<string> names = new List<string> {'name1','name2','some thing else'} ;");
dynamicQuery += ReplaceQuotes("names.Where(i => i.Contains('name')).ToList().ForEach(i => Console.WriteLine(i));");
This time the error being
{interactive}(1,83): error CS1061: Type `System.Collections.Generic.List<string>
' does not contain a definition for `Where' and no extension method `Where' of t
ype `System.Collections.Generic.List<string>' could be found (are you missing a
using directive or an assembly reference?)
I searched in the net and found that people are asking to include System.Core and importing the proper namespaces.
I already have these namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.CSharp;
Then what , where, why is it wrong?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 System.Core 的引用添加到您的项目或编译命令行 (-r:System.Core)
Add a reference to System.Core to your project or compile command line (-r:System.Core)
添加对 System.Core 的引用并将 copy local 设置为 true。
Add a reference to System.Core and set copy local to true.