Is there any problem in Mono.CSharp.dll or I am missing something
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 += Repl开发者_如何学PythonaceQuotes("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
Add a reference to System.Core to your project or compile command line (-r:System.Core)
Add a reference to System.Core and set copy local to true.
精彩评论