Mono.CSharp.dll有什么问题,或者我遗漏了什么

时间:2010-11-23 03:53:14

标签: c#-3.0 mono monodevelop

我从Miguel de Icaza's web site下载了demo-repl.zip文件。

我试图建立某些程序,但都失败了。我的是一个简单的控制台应用程序。

案例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;

那么什么,哪里,为什么这是错的?

由于

2 个答案:

答案 0 :(得分:2)

将对System.Core的引用添加到项目或编译命令行(-r:System.Core)

答案 1 :(得分:0)

添加对System.Core的引用,并将copy local设置为true。