473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Ellegant code generation for generics using reflection.

Hi all,
I'm creating code generator for wrappers of some c# classes. With the
introduction of c# 2.0 and generics the following problem arises.
When encountering generic types anywhere inside the assembly, for
example a generic method parameter declared as:

System.Collections.Generic.List<int>

the full name of that parameter type returned by reflection is :

"System.Collections.Generic.List`1[[System.Int32, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"

This is probably meant to allow runtime creation of that type using
Emit mechanism, I guess.
For the purpose of code generation is quite impractical, because I have
go through all generic types replacing the `1[...] part with the
desired <...>. Although this is not a complicated task, I am suprised
that there is no built-in functionality meant to do that.

Does anybody know if my task can be acomplished without manual string
operations, or the reason why MS haven't added such methods?

Thanks for any comments.
Konrad Kaczanowski

May 11 '06 #1
0 1196

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: MattC | last post by:
Hi, I have a collection class derived from ArrayList, it stores colletions of objects from my objet model. I Didn't want to have to create a specialised collection for each object type so I...
4
by: Gazarsgo | last post by:
This seems to be a bit of a contradiction, but how can I construct a Generic class using a System.Type variable that is assigned at run time? Is there some parallel to the Generics concept that...
1
by: Vladimir Shiryaev | last post by:
Hello! Exception handling in generics seems to be a bit inconsistent to me. Imagine, I have "MyOwnException" class derived from "ApplicationException". I also have two classes...
4
by: Cedric Rogers | last post by:
I wasn't sure if I could do this. I believe I am stretching the capability of what generics can do for me but here goes. I have a generic delegate defined as public delegate bool...
6
by: LordHog | last post by:
Hello all, I recently ran into a strange behavior which I don't understand. I have two 'Add' method which a slightly different signature which they look like public void Add( string varName,...
7
by: Ajeet | last post by:
hi I am having some difficulty in casting using generics. These are the classes. public interface IProvider<PROF> where PROF : IProviderProfile { //Some properties/methods }
4
by: =?Utf-8?B?SGF5U2VlZA==?= | last post by:
Is there some way to use Generics in dynamic code using the Type.GetType("MyClassName") as an argument? List<Type.GetType("MyClassName") oList = new List<Type.GetType("MyClassName") > ...
7
by: colin | last post by:
Hi, Is there a way of doing simple code generation inside visual c# express such as similar to preprocessing in c++ ? I need to generate a library for some vector maths, but I need to...
7
by: =?Utf-8?B?TXJOb2JvZHk=?= | last post by:
Say I have a class that has a generics List as follows: public List<MyClassmyClassList = new List<MyClass>(); and I want to create another class which tries to add an element of MyClass to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.