是否有一个编译器开关来关闭支持泛型在C#中? [英] Is there a compiler switch to turn off support for Generics in C#?

查看:271
本文介绍了是否有一个编译器开关来关闭支持泛型在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正与一个合作伙伴,我们正试图从.NET平台到.NET MicroFramework将一个复杂的驱动程序。

的问题是,.NET MF犯规支持泛型,当我们试图建立的最后一个链接的操作退出,并显示错误codeCLR_E_PARSER_UNSUPPORTED_GENERICS的应用程序。 然而,有没有获得信息WHERE(模块,code线)。

据我们所知,没有人故意插入泛型和他们一直非常期待在code,以确定问题是没有运气的东西。

所以我的问题是:是否有某种方式来关闭支持泛型在Visual Studio 2010,这样编译器就会出错的行

解决方案
  

有没有一些方法来关闭支持泛型在Visual Studio 2010,这样编译器就会出错的行?

是的,但它是一个核选项:

 使用System.Collections.Generic;
类测试
{
    静态无效的主要()
    {
        IEnumerable的< INT> X =零;
    }
}
 


  C:\> CSC / langversion:ISO-1 \ foo.cs
微软(R)的Visual C#2010编译器版本4.0.30319.1
版权所有(C)微软公司。版权所有。

C:\ foo.cs(9,12):错误CS1644:功能'仿制药'不能使用,因为它是
        在ISO-1 C#语言规范不属于
 


ISO-1的开关关闭所有这不是在C#1.0 ,这可能是更多的功能比你要关闭的功能。

请注意,开关不打算成为一个模仿C#在C#2.0编译器1.0开关;如果你想运行C#1.0编译器,只要运行它。开关旨在标识特征的未present在特定版本并禁止它们。

请注意,开关也可能不这样做你需要做的一切。它所做的就是禁止通用的语法的用途。如果您使用的是通用的键入的实际上并没有使用普通的语法的,交换机不会抓住它。

I am working with a partner where we are trying to move a complex driver from the .NET platform to the .NET MicroFramework.

The problem is that the .NET MF doesnt support Generics and when we try to build the application the last "link" operation exits with the error code "CLR_E_PARSER_UNSUPPORTED_GENERICS". There is however no information on WHERE (module, code-line).

As far as we know nobody has intentionally inserted Generics and they have been really looking over the code to identify what the problem is with no luck.

So my question is: Is there some way to turn off support for Generics in VS2010 so that the compiler will flag the offending line ?

解决方案

Is there some way to turn off support for Generics in VS2010 so that the compiler will flag the offending line ?

Yes, but it is a "nuclear" option:

using System.Collections.Generic;
class Test
{
    static void Main()
    {
        IEnumerable<int> x = null;
    }
}


C:\> csc /langversion:ISO-1 \foo.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.

c:\foo.cs(9,12): error CS1644: Feature 'generics' cannot be used because it is
        not part of the ISO-1 C# language specification


The ISO-1 switch turns off all features that were not in C# 1.0, which might be more features than you want to turn off.

Note that the switch is not intended to be a "emulate C# 1.0 in the C# 2.0 compiler" switch; if you want to run the C# 1.0 compiler, just run it. The switch is intended to identify features that were not present in the particular version and disallow them.

Note that the switch also possibly does not do everything you need it to do. All it does is disallow uses of generic syntax. If you are using a generic type without actually using generic syntax, the switch doesn't catch it.

这篇关于是否有一个编译器开关来关闭支持泛型在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆