简体   繁体   中英

which dll contains generics extension methods?

I'm trying to dynamically compile source code using the CodeDom.Compiler stuff, which means I need to reference the basic assemblies manually. The source code that I am compiling must be able to access the basic list extension methods, for for instance, Max(), Min(), or Sum(), and probably lambda expressions as well.

When I compile the source, it says I'm missing the required assembly... currently I include System.dll, and System.Core.dll.

Which dll do I need to get the extension methods for generics?

Have a look at this blog post . You have to specify the compiler version manually when calling the CSharpCodeProvider constructor that receives a dictionary . Like this:

var provider = new CSharpCodeProvider(new Dictionary<string, string>{
                                       {"CompilerVersion", "v3.5"} });

The simple way to get past these type of hassles, is to look through Assembly.GetReferencedAssemblies(), and add references to the compiler that way. Then you know as long as your compiler compiles in Visual Studio, any code using those features will compile with your compiler.

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