I am using C# 2.0 and the CodeDom.
Can someone answer the following 3 questions about the CodeDom in CLR 2.0.
1. I understand that there is no while() loop, only for( ; ; ) loop, can
anyone confirm this.
2. I understand that there is no switch() statement, can anyone confirm
this.
3. I need to create the following code in the CodeDom, can someone show me
how to do this:
String[]s={new String('X', 5),new String('Y',10),new String('Z',15)};
The CodeDom will generate the previous line of code in a loop, so there
could be any number of elements in the String[] array. Is it possible to do
this with the CodeDom, or will i have to generate all the elements one at a
time and then add them by it's index?
Thanks
Russell Mangel
Las Vegas, NV
Greg Young - 05 May 2006 01:13 GMT
1) from
http://msdn2.microsoft.com/en-us/library/system.codedom.codeiterationstatement.aspx
A CodeIterationStatement can represent a for loop or while loop.
This is interesting but I have never actually been able to get it to
generate a while loop ... Maybe someone else on the ng has, if so I would be
quite interested to hear about it! My guess is that the documentation is
wrong
2) from http://blogs.msdn.com/bclteam/archive/2005/03/16/396915.aspx
Switch statement: CodeDom doesn't support a way to generate switch (select
statement in VB) statement. We recommend CodeDom users to use the
'multiple/nested if satements' as a work around.
3) You can define the array values using a CodeArrayCreateExpression
http://msdn2.microsoft.com/en-us/library/system.codedom.codearraycreateexpressio
n.aspx
the particular overload you are looking for is
http://msdn2.microsoft.com/en-us/library/ms131644.aspx which takes a
CodeExpression [] that represents the values to initialize the array with.
http://blogs.msdn.com/roberthorvick/archive/2004/03/15/89818.aspx includes
an example.
Cheers,
Greg
>I am using C# 2.0 and the CodeDom.
>
[quoted text clipped - 18 lines]
> Russell Mangel
> Las Vegas, NV