5

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?

BrainSlugs83
  • 6,214
  • 7
  • 50
  • 56
  • 1
    You can do this with a C# parser. Depending on the level of C# (2, 3, 4, 5), you can pick an ANTLR grammar for example. You could also try Microsoft Roslyn but it's not feature complete. – Simon Mourier Jun 11 '13 at 21:31
  • Yeah, I was hoping to not have to rely on writing my own app; there has to be something out there that someone has already built -- I can't be the first person to run into this issue. :-/ – BrainSlugs83 Jun 13 '13 at 02:06

2 Answers2

1

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.

Erdogan Kurtur
  • 3,630
  • 21
  • 39
  • Unfortunately, the files are not all the same format -- again -- lots of massaging has been done -- some files I had to get a second opinion on from Reflector, etc. -- Many files I've reformatted, added regions, etc. +1 for the comment on checking for legality (#1 above), as well as the reminder you posted at the bottom, of inserting the lines counting from the bottom up -- Also, had to write an automated parser already a while back to fix hundreds of warnings in various code files as well -- and the whole inserting from the bottom to the top thing came in very handy. – BrainSlugs83 Jun 13 '13 at 02:05
  • Oh, another lameness: "Note: This is a technology preview and there are known issues. While the shape of the public API is complete, only a subset of the VB and C# languages have been implemented at this time." – BrainSlugs83 Jun 18 '13 at 02:26
1

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.

John Atwood
  • 1,505
  • 10
  • 19
  • That's actually really cool. I may have to look into this! Though, I'm guessing the formatting is gone, and probably existing comments as well, no? That would make it not an option. But still very cool, new, and shiny! :D – BrainSlugs83 Jun 18 '13 at 02:24