How to reuse type return value to generate new source code

I have this problem:

I want to generate a new source code file from object information.

I am doing something like this:

dictParamMapping is Dictionary<string, Type>where the string is the name of the variable and type is the type of this variable.

I get a type to create new code using:

dictParamMapping[pairProcess.Value].Type.Name (or FullName)

When Type is int, string, datatable, etc., everything works fine, but when it is a dictionary, list, or any other similar, it returns something like:

System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Double, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

It is wrong to build this new source code. I would like to get something likeDictionary<int, double>

Can anyone help me?

+5
source share
2 answers

, # - System.Type. CSharpCodeProvider.

var typeReference = new CodeTypeReference(typeof(Dictionary<int, double>));

using (var provider = new CSharpCodeProvider())
    Console.WriteLine(provider.GetTypeOutput(typeReference));

:

System.Collections.Generic.Dictionary<int, double>

, , . , , (, ), , #.

+3

.NET. .

API, , CodeDOM. , , . , , . CodeDOM #, VB.NET .

+2

All Articles