I’m parsing some DLLs and I have to generate some code that will be compiled.
For the moment, everything works but now, we have to handle Collections<> types and here is the problem.
In the case of an ObservableCollection, we got the Type whose FullName is :
"System.Collections.ObjectModel.ObservableCollection`1[System.String]"
and considering that I’m dealing with objects (I can read anything from the DLL), the code generated should be :
var obj7 = (System.Collections.ObjectModel.ObservableCollection<System.String>) myParsedProperty; //This code will, then, be compiled + executed
So… is there a simple way to do it from the Type or do I have to do some heavy things on Strings ? (manipulating propType.Name .Namespace and .GetGenericArguments() …)
Here is the simplest approach:
Also you can experiment with a Code.Dom: