简体   繁体   English

将XML注释重新插入自动生成的[assembly] .xml文件中的C#源文件树中

[英]Reinserting XML Comments into a tree of C# source files from the auto generated [assembly].xml files

My Situation: 我的情况:
So, I decompiled a .NET assembly with ILSpy into C# last week; 所以,上周我用ILSpy将.NET程序集反编译成C#; since, then, I've put a ton of labour into massaging the files/project, etc. so that they all work correctly again (there were lots of little bugs [mostly caused by ILSpy's code generation process] and random issues and I've been fixing them as I go). 从那时起,我已经投入了大量的精力来按摩文件/项目等,以便它们都能正常工作(有很多小错误[主要由ILSpy的代码生成过程引起]和随机问题而且我我一直在修理它们。 I'm now inches away from my goal, with the finish line in sight! 我现在距离我的目标只有几英寸,终点就在眼前!

But, lo, and behold: I just realized all of the XML comments are missing. 但是,瞧瞧:我刚刚意识到所有的XML评论都缺失了。 >.< > <

I did some scouring and I was able to find the .xml intelli-sense file, with all the Visual Studio generated comments inside. 我做了一些淘洗,我能够找到.xml智能文件,里面有所有Visual Studio生成的注释。

What I would Like to Accomplish: 我想要完成的事情:
I would LIKE to copy these comments from the generated .xml intelli-sense file back into the source files (in an automated fashion of course, as there are about 5000 classes in this Assembly). 我想将这些注释从生成的.xml智能文件复制回源文件(当然,这是自动化的,因为这个程序集中有大约5000个类)。

My Question: 我的问题:
How should I proceed? 我该怎么办? Are there any tools that can do help me automate this task? 是否有任何工具可以帮助我自动执行此任务?

Since code files are generated using a tool (ILSpy), code style and formatting (whitespaces and indentations) will be same for almost every code file. 由于代码文件是使用工具(ILSpy)生成的,因此几乎每个代码文件的代码样式和格式(空格和缩进)都是相同的。 What I would do is 我要做的是

  1. check if decompiling of that 5000+ class library is against the law, 检查5000+类库的反编译是否违法,
  2. write a simple parser to parse code files and find class/method/property definitions 编写一个简单的解析器来解析代码文件并查找类/方法/属性定义
  3. check if what I've found matches with what is in xml 检查我发现的内容是否与xml中的内容匹配
  4. If everything is ok, then I would copy found xml tags to their new position on code files since now that I know positions of definitions in a file. 如果一切正常,那么我会将找到的xml标签复制到他们在代码文件上的新位置,因为现在我知道了文件中定义的位置。

PS: just a reminder, to ease string replacing/inserting, always do inserting from bottom of the file to top of the file. PS:只是提醒一下,为了简化字符串替换/插入,总是从文件底部插入到文件顶部。 this way, whenever you insert a line, indexes of other lines to be inserted will remain same. 这样,每当插入一行时,要插入的其他行的索引将保持不变。

You could use the Roslyn CTP for C# to make a tool that would reinsert the comments into the source files. 您可以使用Roslyn CTP for C#来创建一个将注释重新插入源文件的工具。 ( http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx ) Roslyn creates a tree like structure of your C# code that you can manipulate programmatically and then write back to a file. http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx)Roslyn创建了一个类似C#代码结构的树,您可以通过编程方式操作然后写回文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM