Net有道

紫冠道人的求道历程

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

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

 

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

 

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

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

posted on   lichdr  阅读(5717)  评论(12编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示