动态生成与编译(九)----CodeDOM的局限

来源:百度文库 编辑:神马文学网 时间:2024/04/29 23:25:05

动态生成与编译(九)----CodeDOM的局限

 

CodeDOM这个东西虽然能生成大多数的程序代码,但它还是有点局限性的喽。我在写CodeDOM程序中就碰到过一些了,虽然有些特性是可以用其他方法代替的,但有些代码还是无法用CodeDOM写出来 。本来就是要写些最近在CodeDOM中碰到的问题的,但前两天在CodeProject上发现有人已经做过这样的事了http://www.codeproject.com/csharp/codedomparser.asp,虽然是两年前的文章,而且是在.NET1.0下的,但是比较的全面(有很多我还没碰到过,也没想到过,有几句还看得迷迷糊糊的),而且看来对CodeDOM来讲.NET1.0与NET1.1差别不大(可能没差别,没仔细确认过)。

  • CodeCompile unit does not have space for using directives or ns members, so they are placed now into first default NS //这句不是很明白,“not have space”直译就是没有间隔的意思啦,但好象这不应该是问题。后面”so they….”也不太懂,如果是说using进来的程序集都放到第一个命名空间去了也不是,这点CodeDOM现在是能搞定的
  • using_alias_directive - no support found
  • nested namespaces - no support found ( so parser is flattening ns hierarchy)
  • variable declaration list (int i,j,k;) - no support - transformed to individual var declarations
  • pointer_type - no support found
  • "jagged" array type (array of arrays) - MS CSharpCodeProvider reverses order of ranks
  • params keyword - not supported - param is omitted in parsing and param is then an ordinary array type param
  • private modifier on nested delegate is not shown by CSharpCodeProvider (all other nested types works fine) //不过我试过无论是如何设置,无论什么的内嵌类型,最后都成public
  • unsafe modifier - no support found
  • readonly modifier - no support found
  • volatile modifier - no support found
  • explicit interface implementation - not implemented yet (I think this can be done)
  • add and remove accessors for Event - no support found
  • virtual and override modifiers do not work in MS CSharpCodeProvider for events //事件也有override的吗?
  • Operator members and Destructors - no support found
  • Expressions - no unary expressions(operations) at all !!!, only one dim arrays, some operators not supported and more

/*下面这两个不是很清楚,Attribute targets与Attributes on accessor是什么意思呀。本来对.NET里的Attributes这东西就不是很熟悉。*/

  • Attribute targets : no support found
  • Attributes on accessor : no support found

 

  • If CompileUnit contains custom attributes in global scope, CSSharpCodeProvider prints then before global using directives (it is due to that using has to be in the first ns) //这个是不是说单元级的一些attributes。因为在CodeDOM里只有namespace是有引用程序集的,而CompileUnit是没有Import namespace功能的,好象是说无法设置assembly级的attributes的意思?

PS:除了上面提到过的,在C#里的using语句也没有出现,看来在CodeDOM里这个using出的问题大了,只有引用程序集的那个using问题不大。后面在程序中我就直接用try…finally结构来代替using了。不过这是特定语言的问题,问题不大,而且有替代方法。

 

以上的都是类编写过程中碰到的问题为主,现在写的程序当然也是以上面的那些东西为多,去动态生成也主要是生成大同小异的类比较的多点。

在流程控制方面,CodeDOM对while、do…whle循环好象无能为力,没有if…else if…else if……else这种及switch(或select)这些多选择的语句。而且也没有break、continue这样的跳转语句,只有goto语句。一些跳转方面的可能是比较的特殊的需求了,程序要动态到这种程度也没什么的意思,但多分支选择,特别是switch这种的选择语句,来动态生成有时候还是有需要的,怎么会没有呢?