Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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; 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). 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. >.<

I did some scouring and I was able to find the .xml intelli-sense file, with all the Visual Studio generated comments inside.

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).

My Question:
How should I proceed? Are there any tools that can do help me automate this task?

like image 658
BrainSlugs83 Avatar asked Nov 02 '22 20:11

BrainSlugs83


2 Answers

You could use the Roslyn CTP for C# to make a tool that would reinsert the comments into the source files. (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.

like image 168
John Atwood Avatar answered Nov 15 '22 04:11

John Atwood


Since code files are generated using a tool (ILSpy), code style and formatting (whitespaces and indentations) will be same for almost every code file. What I would do is

  1. check if decompiling of that 5000+ class library is against the law,
  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
  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.

PS: just a reminder, to ease string replacing/inserting, always do inserting from bottom of the file to top of the file. this way, whenever you insert a line, indexes of other lines to be inserted will remain same.

like image 34
Erdogan Kurtur Avatar answered Nov 15 '22 06:11

Erdogan Kurtur