[antlr-interest] C# issue about action code with generic type.

Sam Harwell sharwell at pixelminegames.com
Mon Aug 30 06:16:38 PDT 2010


In C#, generic type parameters are resolved at compile time. Your code
results in the following:

var _list = new List<"System.String">();

instead of the following valid line:

var _list = new List<System.String>();

One option for your code is using the non-generic ArrayList type. Here's an
additional reference:
http://stackoverflow.com/questions/266115/pass-an-instantiated-system-type-a
s-a-type-parameter-for-a-generic-class

Sam

-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.
org] On Behalf Of ??
Sent: Monday, August 30, 2010 3:16 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] C# issue about action code with generic type.

Hi, All,

I encounter some troubles when try to embedded action code with generic type
in C#. Here is my case:

 list: LIST_TYPE { var _list = new List<$LIST_TYPE.text>();  }
     ;

My purpose here is getting generic type from LIST_TYPE, and create a generic
list, such as List<string>, List<int> and so on. However, $LIST_TYPE.text
returns a string value, which makes compile failed. Any suggestion?


--
Han kai

"To iterate is human, to recurse divine." - L. Peter Deutsch

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list