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

}

 

Generate:

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

{

  [field:NonSerialized]

  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.