Thanx for the quick response. Almost good. The "MakeArrayType" method is
available only in .NET2.0, but a solution would be needed for v1.1. Any other
ideas?
> You do it with Type.MakeArrayType().
> Thanx for the quick response. Almost good. The "MakeArrayType" method is
> available only in .NET2.0, but a solution would be needed for v1.1. Any other
> ideas?
The only other way I know to create that guy is to use
Array.CreateInstance and get the type of the return value, which would
be quite an awkward workaround.
-- Barry

Signature
http://barrkel.blogspot.com/
> Thanx for the quick response. Almost good. The "MakeArrayType" method is
> available only in .NET2.0, but a solution would be needed for v1.1. Any
> other
> ideas?
ModuleBuilder.GetType seems to be promising.... it handles [], *, & for
arrays, pointers and references. If any of those are present, it ends up
calling:
private Type GetType(string strFormat, Type baseType)
{
if ((strFormat == null) || strFormat.Equals(string.Empty))
{
return baseType;
}
char[] chArray1 = strFormat.ToCharArray();
return SymbolType.FormCompoundType(chArray1, baseType, 0);
}
And FormCompoundType looks like just what you ordered. In fact, you might
be able to get away with directly calling this overload of GetType via
reflection, but myDynamicModule.GetType(myTypeBuilder.FullName + "[]") looks
like the approved way.
Of course, you can use another MSIL-creation tool, such as Phoenix
(http://research.microsoft.com/phoenix/) which gives you complete control.
>> You do it with Type.MakeArrayType().
Barry Kelly - 21 Jul 2006 01:03 GMT
> > Thanx for the quick response. Almost good. The "MakeArrayType" method is
> > available only in .NET2.0, but a solution would be needed for v1.1. Any
[quoted text clipped - 3 lines]
> ModuleBuilder.GetType seems to be promising.... it handles [], *, & for
> arrays, pointers and references.
It would be cool if that works. I note that the .NET 2 docs have this
stern warning in the Remarks section:
"Do not use this method to generate array types, pointer types, or byref
types. Use the TypeBuilder.MakeArrayType, TypeBuilder.MakePointerType,
and TypeBuilder.MakeByRefType methods instead."
... but that only really makes sense if those methods exist before 2.0.
-- Barry

Signature
http://barrkel.blogspot.com/
Edgile - 21 Jul 2006 08:12 GMT
> but myDynamicModule.GetType(myTypeBuilder.FullName + "[]") looks
> like the approved way.
Hello guys,
Thanx for this fascinating fast response time. This proposal works fine, I
am happy!
"Barry Kelly" wrote:
> Array.CreateInstance and get the type of the return value, which would
> be quite an awkward workaround.
Yes, it is awkward but I tried it before I submitted my trouble here. It
does not work. After I tried, I recognized that it obviously cannot work as
creating an instance of a type under construction is far from a good solution
:)
Thanks again for you kindness and help!
Barry Kelly - 21 Jul 2006 08:44 GMT
> Yes, it is awkward but I tried it before I submitted my trouble here. It
> does not work. After I tried, I recognized that it obviously cannot work as
> creating an instance of a type under construction is far from a good solution
Yes, you'd need to create the whole module before you create the type. A
third way is to output IL instead, and call ILASM. But, it's great you
found a solution!
-- Barry

Signature
http://barrkel.blogspot.com/
Ben Voigt - 21 Jul 2006 15:09 GMT
>> Yes, it is awkward but I tried it before I submitted my trouble here. It
>> does not work. After I tried, I recognized that it obviously cannot work
[quoted text clipped - 5 lines]
> third way is to output IL instead, and call ILASM. But, it's great you
> found a solution!
But the array was supposed to be a static member of the type itself.... I do
that a fair amount myself actually, though not through Reflection.Emit.
Thankfully, I get to use .Net 2.0 exclusively now as well. But Reflector's
search for methods containing the word array, sorted by namespace, plus a
little browsing around, came up with the answer pretty quickly.
> -- Barry
Barry Kelly - 21 Jul 2006 15:23 GMT
> But the array was supposed to be a static member of the type itself....
I know!
> I do
> that a fair amount myself actually, though not through Reflection.Emit.
> Thankfully, I get to use .Net 2.0 exclusively now as well.
I managed to get .Net 2.0 adopted when it first came out CTPs and early
beta, so I never had to deal with these issues in my own codegen :)
-- Barry

Signature
http://barrkel.blogspot.com/