腾讯微群加入QQ群

 找回密码
 加入我们

!connect_header_login!

!connect_header_login_tip!

搜索
查看: 2248|回复: 0

CodeDom Assistant CodeDom的强大工具, 有些BUG修正了下,发到CodePlex了

[复制链接]
发表于 2012-5-21 11:04:18 | 显示全部楼层 |阅读模式
一、第一次编译并调整代码
二、修正泛型无法生成CodeDOM代码
后期我会用到这个工具, 如果有需要修改, 会及时修改和改进, 有兴趣的可以参与进来。 http://codedomassistant.codeplex.com/


Generating CodeDom Code By Parsing C# or VB
使用C#或者VB生成CodeDom代码



Introduction

I find writing CodeDom code kind of like writing assembly. It's like cutting the grass with a pair of scissors or unloading a truck load of sand with a spoon. Its long winded, it can be done, but it is tedious. However, there are advantages in using CodeDom.

Now, it would be nice if you could whip up a class in VB or C# and generate the CodeDom code. CodeDom Assistant does this with the help of SharpDevelop's NRefactory Library in conjunction with writing our own CodeDomProvider to generate C# CodeDom code. The code you get will construct a CodeDom compileunit, and it will definitely be ugly. But what can you expect from a machine?

Background

Code Generation can be done using various techniques. In essence, code generation saves time, and enables you to create code using established patterns.

In the world of .NET, one technique is to use CodeDom. It allows you create a document object model of the code. This can by either compiled into an assembly or used to generate code. Every .NET language should have an implementation of a CodeDomProvider to generate code. The problem is that CodeDom does not implement every syntax construct of every language. In essence, it is a subset, but there are enough operations to emulate most language constructs.

Parsing C# or VB is going to be the toughest part, but luckily one of SharpDevelop's little libraries is NRefactory. This has the machinerary required to parse C# or VB code. The key component for us is the CodeDomVisitor class. Sadly, it is only a partial implementation. They implement enough to run SharpDevelop's form generation. I am not saying I have completed the implementation, rather, I have filled most of the holes in the CodeDomVisitor.

The second part is implementing a CodeDomCodeProvider. This will take a CodeDom compile unit and generate C# code that will create a CodeDom compile unit.

License
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

About the old Version  Author

raygilbert
http://www.codeproject.com/Articles/20597/CodeDom-Assistant
http://www.codeplex.com/Download?ProjectName=codedomassistant&DownloadId=381289
http://download.codeplex.com/Download?ProjectName=codedomassistant&DownloadId=381290

About New Version Author
MysticBoy
http://www.mysticboy.cn


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

QQ|手机版|Archiver|小黑屋|一起疯|苦咖啡 ( 新ICP备12000197号  

GMT+8, 2018-1-20 12:40 , Processed in 0.051927 second(s), 14 queries , Memcache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表