Jb has already answered the array question for you. In order to wrap
something in List<T>, simply use “new GenericInstanceType(...)”
instead.

However, note that the result is *not* a TypeDefinition.
TypeDefinition only refers to real types that are actually declared in
your assembly. ArrayType and GenericInstanceType will be subclasses of
*TypeReference*, which is used to *refer* to types rather than
*define* them. Of course, TypeDefinition is itself a subclass of
TypeReference so that it can be used to refer to the type itself.

All of this could probably be simply explained in an XML comment on
the classes in Mono.Cecil, but Jb refuses to add any of those without
explaining to us why.

Timwi


On Dec 6, 1:03 pm, impworks <[email protected]> wrote:
> Hello!
>
> Is there any way to programmatically turn a type described by
> TypeDefinition to an array of that type?
>
> I'm trying to create a compiler for a language, in which the user can
> declare variables as:
>
> <code>
> int a;
> int[] b;
> int[][] c;
> </code>
>
> and so on. The trick is, I don't know the arity of the the array the
> user desires to create, and the type may be built-in or user-defined
> too.
> When working with System.Type, I can create an array using this block
> of code:
>
> <code>
> var someType = typeof(MyType);
> var arrayType = someType.MakeArrayType();
> </code>
>
> The same way, I need to be able to wrap a type into a List<T>.
>
> Is there any analog that works like this on a TypeDefinition instead
> of Type? Or maybe I can get a Type out of TypeDefinition, process it
> and create a new TypeDefinition by using Assembly.MainModule.Import() ?

-- 
--
mono-cecil

Reply via email to