让 NDoc 1.3 支持.NET 2.0 程序集,泛型输出和 Visual studio 2005 解决方案导入

最近要做一份sdk手册,就找到NDOC ,到官方下载了最新的版本 NDoc 1.3 英文版安装包,结果发现支持.NET 1.1的程序集的文档生成,因为内部使用了反射机制,那么要支持.NET 2.0 的程序集很简单;

办法有两个:
1、用VS2005 重新编译一下
2、编写一个NDocGui.exe.config,直接指定版本,内容如下

None.gif < configuration >
None.gif < startup >
None.gif < supportedRuntime version ="v2.0.50727" />
None.gif </ startup >
None.gif </ configuration >

ok,经过上面的任何一步之后,就已经支持了.NET 2.0 环境了,但是他是全英文的,生成出来的文档不能达到要求;经过寻找,确定了国内的一个汉化版本,作者是“破宝(percyboy)”,看了测试的效果非常不错,感谢。

http://www.percyboy.com/w/ndoc/ 下最新的汉化版本和它的汉化版本的原始代码;经过比较,它也是基于.NET 1.1 环境,仅支持Visual Studio.net 2003 解决方案导入,那么它仅仅只是汉化了资源,代码部分应该和英文版本的差不多;

首先解决.NET 2.0 环境问题,打开visual studio 2005编译一次,即可。

Visual studio 2005 解决方案导入,核心的代码是NDoc里的VisualStudio工程,下载这个代码包,覆盖原始工程,重新编译即可。解决.NET 2.0 的程序集内有泛型的类或方法,将产生异常,具体错误是 (Type == null) 而访问.FullName 属性,那么将Core工程的ReflectionEngine.cs 类打开,增加该函数:

None.gif private static string GetFullName(Type type)
ExpandedBlockStart.gif ContractedBlock.gif dot.gif {
InBlock.gifstring name;
InBlock.gifif (type.FullName == null)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif Type result = null;
InBlock.gifif (type.IsGenericType && !type.IsGenericTypeDefinition)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif result = type.GetGenericTypeDefinition();
ExpandedSubBlockEnd.gif }
InBlock.gifelse if (type.IsGenericParameter || type.ContainsGenericParameters)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gifreturn type.Name;
ExpandedSubBlockEnd.gif }
InBlock.gifif (result == null || result.FullName == null)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gifthrow new ArgumentException("Incomplete type: " + (result != null ? result : type), "type");
ExpandedSubBlockEnd.gif }
InBlock.gif name = result.FullName;
ExpandedSubBlockEnd.gif }
InBlock.gifelse
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif name = type.FullName;
ExpandedSubBlockEnd.gif }
InBlock.gifreturn name;
ExpandedBlockEnd.gif}


并且将内部那些以 private string Get....(Type type) 命名的函数内部的 type.FullName 都修改为该函数的调用形式即可。
如:

None.gif private string GetMemberName(Type type)
ExpandedBlockStart.gif ContractedBlock.gif dot.gif {
InBlock.gif//原始的为 return "T:" + type.FullName.Replace('+','.');
InBlock.gif
return "T:" + GetFullName(type).Replace('+', '.');
ExpandedBlockEnd.gif}

如果觉得麻烦也没关系,直接下这个代码覆盖;

/Files/Chinasf/ReflectionEngine.rar

以上修改都是基于中文汉化版本修改的,请自行测试。另外再次感谢汉化工作者所做的辛勤劳动,让我工作起来得心应手!

9:58 2006-6-8




本文转自suifei博客园博客,原文链接:http://www.cnblogs.com/Chinasf/archive/2006/06/08/NDoc2005.html,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值