解析c#程序集的注释xml文件,自动生成aardio智能解析库源码
By
admin
at 2022-03-11 • 0人收藏 • 929人看过
import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=776;bottom=459;acceptfiles=1) winform.add( button={cls="button";text="Open";left=695;top=412;right=774;bottom=439;db=1;dr=1;z=3}; edit={cls="edit";left=2;top=413;right=695;bottom=440;autohscroll=false;autovscroll=false;db=1;dl=1;dr=1;edge=1;hidesel=1;z=2}; edit2={cls="edit";left=0;top=0;right=777;bottom=410;db=1;dl=1;dr=1;dt=1;edge=1;hidesel=1;hscroll=1;multiline=1;vscroll=1;z=1}; progress={cls="progress";left=2;top=447;right=777;bottom=457;db=1;dl=1;dr=1;edge=1;max=100;min=0;z=4} ) /*}}*/ var convertXML = function(path){ var str = string.load(path); var member_pattern = //\<member name=\"(.*?)\"\>(.*?)\<\/member\> var summary_pattern = //\<summary\>(.*?)\<\/summary\> var param_pattern = //\<param name=\"(.*?)\"\>(.*?)\<\/param\> var returns_pattern = //\<returns\>(.*?)\<\/returns\> var 总条数 = #string.matches(str,member_pattern); winform.progress.setRange(0,总条数); winform.progress.pos = 0; for name,summary_param in string.gmatch( str, member_pattern ){ winform.progress.pos++; name = string.replace( name, "\[(.*?)\]", "[]"); name = string.replace( name, "System\.Nullable\{(.*?)\}", "\1"); name = string.replace( name, "System\.Action\{(.*?)\}", "\1"); name = string.replace( name, "@.#ctor", ""); var name = string.split(name,'<:>'); if(name[[2]]){ var summary = string.matches(summary_param,summary_pattern)[[1]][[1]]; if( summary ){ summary = string.trim(summary); summary = string.replace(summary,'\r\n',"\\n"); } select(name[1]) { case "N" {//名字空间 } case "T" {//类型,包括类、接口、结构体、枚举和委托 } case "F" {//字段 } case "P" {//属性 } case "M" {//方法,包括普通方法、构造函数和运算符重载 if(!string.indexOf(name[[2]],")")){ name[[2]] = string.concat(name[[2]],"()"); }else { var part = string.matches(name[[2]],"%()"); if(part[[1]][[1]]){ var placepart = string.replace(part[[1]][[1]],"@.","_"); name[[2]] = string.replace(name[[2]],"@"++part[[1]][[1]],placepart); } name[[2]] = string.replace(name[[2]],'<(>','(.('); } } case "E" {//事件 summary = string.replace(summary,"@\n",'\r\n'); var funTab = string.split(name[[2]],'<.>'); summary = string.concat("@.",funTab[[#funTab]],' = function(){\r\n','\t',"/***",summary,"***/",'\r\n\t__\r\n}'); } case "!" {//错误成员,一般是由于编译器无法识别指定的成员类型,例如 <see cref="MemberNotExists"/>,就会被编译器转换为<see cref="!:MemberNotExists"/> } else { } } for iname,param in string.gmatch( summary_param, param_pattern ){ param = string.replace(param,"\r\n",""); summary = string.concat(summary,"\n",iname," : ",param,"\n"); } var returns = string.matches(summary_param,returns_pattern)[[1]][[1]]; if(returns){ returns = string.replace(returns,"\r\n",""); summary = string.concat(summary,"\n return :",returns); } var saveStr = string.concat(name[[2]]," = ",summary,'\r\n'); winform.edit2.log( saveStr ) string.save("\externXML.txt", saveStr,true) } } } winform.onDropFiles = function(files){ if(#files>0){ winform.edit.text = files[1]; convertXML(files[1]); } } import fsys.dlg; winform.button.oncommand = function(id,event){ var path = fsys.dlg.open("注释文件|*.xml","选择程序集注释文件"); if(path){ winform.edit.text = path; convertXML(path); } } winform.show(); win.loopMessage();
1 个回复 | 最后更新于 2022-03-16
登录后方可回帖
回复#1 @admin :
你的Xml解析工具挺好用的,不过里面有个地方会报错,第34行,如果遇到summary是空的时候,改为下面代码就可以了,加个判断。