none
CODEDOM: Limitations of Codedom

    Question

  •  

      I have following questions,

     

    1. What are the limitations of System.Codedom in .NET 2.0?
    2. What changes are expected in System.Codedom in .NET 3.0?

      Please provide authentic links if possible.

    Thursday, April 19, 2007 3:57 AM

Answers

  • You can not generate (directly) something which is not in:
    http://msdn2.microsoft.com/en-us/library/f1dfsbhc.aspx

    But be aware that if you can generate the CodeDom, it does not mean you can generate code with it!

    See the following link for a list of things that are not supported by all CodeDomProvider:
    http://msdn2.microsoft.com/en-us/library/system.codedom.compiler.generatorsupport.aspx
    As you can see the list is quite large!

    Using some code transformation, you can transform some C# statements in CodeDom. Ex:
    int i = (a?b:c)+5;
    =>
    int temp__; if (a)   temp__ = b; else temp__ = c;
    int i = temp + 5;

    Using some equivalent construction, you can transform some C# statement in CodeDom. Ex: while loop into for loop, switch into if+label+goto.

    Using some CodeSnippet, you can write your own sugar (ex: [1]).

    Otherwise you can use some functions in a dll, or in the .Net Framwork.
    ex: a is b
    =>(Object.ReferenceEquals(var, null) == false && typeof(type).IsAssignableFrom(var.GetType()))

    Some other things are not possible, but are not vital, or you can go close to it.
    ex: static class A{ /*foobar*/}
    => sealed class A{private A(){} /*foobar*/}

    Also, some things seems possible, but do not generate correct code, for example the struct constraint[2].

    At the end, there is no limitation, because you can write your own CodeDomProvider. This can be simple if you build it on top of an existing CodeDomProvider.

    For the .Net3, the CodeDom should not change (no time to find a reference).

    Regards
    Sorry, the following links are not official (written by me, there are some error that I will correct one day...):
    [1] http://metasharp.net/index.php?title=More_technical_Csharp#Ternary_if_.28condition.3FifTrue:ifFalse.29
    [2]http://metasharp.net/index.php?title=More_technical_Csharp#Generating_the_struct_constraint




    Thursday, April 19, 2007 9:35 AM