baskaran

hi,

I want to generate switch block using codeDOM. Is it possible

If yes, which codeDOM class provide switch block creation

if no, whats the alternative

Thanks in advance




Re: .NET Base Class Library does codeDOM supports switch block generation

nielsvanvliet

No.
Solution 1.
You can use CodeConditionStatement (if), if your switch is basic (no goto statements).

Solution 2.
If your switch contains goto statement, you can use a list of label for each enum (using CodeLabeledStatement) plus two special ones (on label to emulate the default, one for the break (i.e. end of switch)). After each lablel the write the corresponding code of each 'case' (including the goto, to a case, or to default, or a to the label label_break). At the begining of this list use a tree of CodeConditionStatement to swith to the corresponding label.
This produce a code language independant (but not very human friendly).

Solution3.
You can use snippet code. To generate yourself the line C# switch structure.
An example of how to combine code generation with CodeSnippet is provided here:
http://metasharp.net/index.php title=More_technical_Csharp#Ternary_if_.28condition.3FifTrue:ifFalse.29

Regards





Re: .NET Base Class Library does codeDOM supports switch block generation

baskaran

hi nielsvanvliet,

I got your point and i saw your article too. Now i finish creating switch block using CodeSnippet. I want to ask you one question, codeDOM classes provide support for deletegate generation too. Then why codeDOM classes doesn't provide direction creation of switch block. Do you have any idea regarding this.

And codeDOM also didnt support "foreach" creation and "while" loop creation too. Instead of while loop i use "for" only because codeDOM doesn't create while loop. These are some drawbacks of codeDOM that i know.

Can you give me a list of features( which are all not supported by codeDOM).

Thanks in advance.






Re: .NET Base Class Library does codeDOM supports switch block generation

nielsvanvliet

The smallest is the subset of things you can do, the easiest it is to implement the CodeDomProvider for a particular language.

It is the same idea than the CLS (why int are CLS compliant and uint are not ). If you have a small kernel, it is easier to interface very different languages.

I provide a list of what can be generate here:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1492814&SiteID=1&mode=1