Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a compiler switch to turn off support for Generics in C#?

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 ?

like image 377
Ronny Avatar asked Nov 28 '22 10:11

Ronny


1 Answers

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.

like image 135
Eric Lippert Avatar answered Dec 19 '22 01:12

Eric Lippert