Language features which can’t be expressed using CodeDOM in Whidbey. [Vinaya Bhushana Gattam Reddy]

The CodeDom provides a powerful way for applications to emit source code in a variety of languages.  CodeDom provides necessary infrastructure to generate common language features that are necessary across the languages instead of providing ways to generate every single feature that a high level languages supports. This blog entry lists some known C# and VB language features that we won’t be able to generate in Whidbey (I’m explicitly saying Whidbey because some of these we may support in the next release).


Unary Operator: Currently CodeDom doesn’t provide a way to generate unary operator (negation for example). We have had several requests for this. We may consider adding the support for this feature in the next release because almost all languages support this concept. The simple work-around is to have a binary operator expression and compare to Boolean True or False. It’s not pretty, but readability is not a primary goal for CodeDom.


Read-only fields: Currently CodeDom doesn’t support a way to generate Read-only field values. No simple work around other than the snippet statement.


Break and continue support: Currently CodeDom doesn’t provide a way mechanism to generate break and continue statements. We may consider adding these in the next release. CodeSnippetExpression is your friend now.


Is/As Support: Currently CodeDom doesn’t provide a way to generate these keywords. There is no good way to work around this.


While statement: CodeDom doesn’t provide a way emit while statement. We recommend CodeDom users to use the ‘for loop’ as a work around.


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.


Set attributes for getter/setter of a property: Currently CodeDom doesn’t provide a mechanism to apply attributes at the getter/setter level. No work around.


C# Entry point method: CodeEntryPointMethod always generates void Main in C# even if the return type is explicitly set to int. No work around for this and we will address this in the next release.


ValueInequality Opetator: Currently we don’t support ValueInequality in CodeBinaryOperatorType.  You could use an unattractive workaround, e.g. instead of

if (a != b) {

          // Do something




if (a == b) {


else {

          // Do something



Internal virtual: CodeDom currently doesn’t support a way to generate “"internal virtual". We have plans to re-visit the logic that we use to interpret TypeAttributes and MemberAttributes usage to generate different possible access level modifiers in the next release.


Indexers in VB: VB Code Provider doesn't provider a way to create default indexers that are not named as "Item".  No work around.


No way to generate field only attribute on an event: Currently CodeDom doesn’t support any way to generate customAttribute on the field part of an event as shown below.

public class MyClass



  event MyEventHandler eventHander;



This is not a comprehensive list. This is a good list to start with and I will try to update this list again some time soon.

Comments (12)

  1. Anonymous says:

    For a technology for which one of the goals is to generate code in user editable files (at least that is how I understood CodeDOM), there is another feature that seems to be missing: support for regions.

    For languages that don’t support regions, a ‘region’ in the CodeDOM tree could simply be handled as a no-op. For languages that do support them, regions are a really great way to indicate that certain parts of the code were generated, which is really helpful when maintaining the code (or other forms of "reading someone else’s code".

  2. Anonymous says:

    Thanks for the comments Luc. We have added regions support in Whidbey. The Beta2 bits will be available in the near future. keep an eye on the msnd site for updates on this:

  3. Anonymous says:

    There is no support from ParamArrayAttribute. Although one can define a ParamArrayAttribute on a parameter, which will work fine in VB, the generated C# code will fail to compile because the params keyword must be used.

  4. Anonymous says:

    There is no support for conditional operator (?:). Work around is using if statements, but in many cases conditional operator would be nicer

  5. Anonymous says:

    There is no support for do-while statements. Implementing it as a for loop is not straight forward like while.

  6. Anonymous says:

    The most important drawback in current CodeDom implementation is that CSharpCodeGenerator and VBCodeGenerator classes are internal. So one cannot inherit and extend them to implement the missing parts.

  7. Anonymous says:

    In my last post I said the most annoying drawback in CodeDom is that Code Generation classes are internal, therefore one cannot inherit and extend them in order to implement the missing parts.

Skip to main content