.Net运行时编译器是否支持C#3.0?

时间:2021-12-27 03:13:07

It looks like the run-time compiler doesn't support the same language as the command-line compiler so if you want to use lambda expressions, extensions methods or LINQ, well, you're stuck.

看起来运行时编译器不支持与命令行编译器相同的语言,所以如果你想使用lambda表达式,扩展方法或LINQ,那么你就会陷入困境。

There's more detail here:

这里有更多细节:

http://metadatalabs.com/blog/

Is this correct or is there a work-around? (Short of spawning the command-line compiler, of course.)

这是正确的还是有解决方法? (当然,没有产生命令行编译器。)

4 个解决方案

#1


1  

This guy's blog seems to have the answer

这家伙的博客似乎有答案

CodeDomProviders

Looks like the factory defaults the instance it returns to 2.0.

看起来工厂默认它返回2.0的实例。

This seems like a pretty crazy technique. Somewhere Paul Graham is crying.

这似乎是一种非常疯狂的技术。保罗格雷厄姆某处哭了。

#2


2  

I've been using this, and it seems to work when compiling using .Net 3.5

我一直在使用它,它似乎在使用.Net 3.5进行编译时起作用

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

#3


2  

Take a look at the documentation of the CSharpCodeProvider constructor:

看一下CSharpCodeProvider构造函数的文档:

The value for providerOptions is obtained from the element in the configuration file. You can identify the version of the CSharpCodeProvider you want to use by specifying the element, supplying "CompilerVersion" as the option name, and supplying the version number (for example, "v3.5") as the option value. You must precede the version number with a lower case "v".

providerOptions的值是从配置文件中的元素获取的。您可以通过指定元素,提供“CompilerVersion”作为选项名称,并提供版本号(例如,“v3.5”)作为选项值来标识要使用的CSharpCodeProvider的版本。您必须在版本号之前加上小写“v”。

#4


0  

I haven´t tried that, but it sounds crazy..

我没试过,但听起来很疯狂..

In the future that wont be a problem, since the .NET team are going to have the C# compiler available as a service, which means you can work with the real C# compiler in your code. Take a look at this video:

在将来不会出现问题,因为.NET团队将把C#编译器作为服务提供,这意味着您可以在代码中使用真正的C#编译器。看看这个视频:

http://channel9.msdn.com/pdc2008/TL16/

#1


1  

This guy's blog seems to have the answer

这家伙的博客似乎有答案

CodeDomProviders

Looks like the factory defaults the instance it returns to 2.0.

看起来工厂默认它返回2.0的实例。

This seems like a pretty crazy technique. Somewhere Paul Graham is crying.

这似乎是一种非常疯狂的技术。保罗格雷厄姆某处哭了。

#2


2  

I've been using this, and it seems to work when compiling using .Net 3.5

我一直在使用它,它似乎在使用.Net 3.5进行编译时起作用

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

#3


2  

Take a look at the documentation of the CSharpCodeProvider constructor:

看一下CSharpCodeProvider构造函数的文档:

The value for providerOptions is obtained from the element in the configuration file. You can identify the version of the CSharpCodeProvider you want to use by specifying the element, supplying "CompilerVersion" as the option name, and supplying the version number (for example, "v3.5") as the option value. You must precede the version number with a lower case "v".

providerOptions的值是从配置文件中的元素获取的。您可以通过指定元素,提供“CompilerVersion”作为选项名称,并提供版本号(例如,“v3.5”)作为选项值来标识要使用的CSharpCodeProvider的版本。您必须在版本号之前加上小写“v”。

#4


0  

I haven´t tried that, but it sounds crazy..

我没试过,但听起来很疯狂..

In the future that wont be a problem, since the .NET team are going to have the C# compiler available as a service, which means you can work with the real C# compiler in your code. Take a look at this video:

在将来不会出现问题,因为.NET团队将把C#编译器作为服务提供,这意味着您可以在代码中使用真正的C#编译器。看看这个视频:

http://channel9.msdn.com/pdc2008/TL16/