简体   繁体   中英

CSScript: Inject System.linq inside “CreateFunc”

This code:

 func = CSScript.CreateFunc<int>(@"int f(int[] inputs) { return inputs.Max(); }");

 int max = func(new int[]{ 235,123,675,111 });

is throwing:

error CS1061: 'System.Array' does not contain a definition for 'Max' and no extension method 'Max' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

I need to inject System.Linq inside my function " func "

.... How can I do that?

This is from the CS-Script Documentation :

Hints And Tips

When you need to reference many assemblies (and particularly when these assemblies are commonly used) it is convenient to combine all //css_reference statements into single file containing no code and include this file into your primary script.

The following code includes linq.includes.cs file containing references to all assemblies required for programming against LINQ:

 //css_include linq.includes.cs; using System; class Test { static public void Main( string [] args) { .... 

This is the content of the linq.includes.cs file:

 //css_ref System.Core; //css_ref System.Data.ComponentModel; //css_ref System.Data.DataSetExtensions; //css_ref System.Xml; //css_ref System.Xml.Linq; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM