tags:

views:

128

answers:

2

I have a dll which I disassemble in Reflector, I then generate a class. The class contains code which does not compile in Visual Studio.

I take it it's leagl IL code, but how can I generate the higher level c# from this.

Seems yield and IEnumerator generate things like <>1__state; in the IL which will not compile.

Does anybody know how I can generate a class from reflector that contains this sort of IL?

Is there a reflector addin that will solves this?

    private sealed class <Rule_Document>d__0 : IEnumerable<HtmlTag>, IEnumerable, IEnumerator<HtmlTag>, IEnumerator, IDisposable
    {
        private int <>1__state;
        private HtmlTag <>2__current;
        public HtmlParser <>4__this;
        private int <>l__initialThreadId;
        public HtmlTag <htmlTag>5__1;
+7  A: 

That IL is from an iterator block. Iterators are horrible to write manually, and the underlying IL from an iterator block is testament to the reality of what the compiler does for you. Be grateful you didn't have to do it yourself!

You could try putting that together mainly from the MoveNext(), but don't expect miracles. You may also find that renaming the fields (to get rid of things like <> prefixes) goes a long way.

However; I expect the best thing to do is to understand what the code is trying to do, and stop trying to simply steal borrow their implementation.

Marc Gravell
+1, I agree. If the author of the code wanted other people to read/modify it he would simply release the source code.
Darin Dimitrov
@Marc Gravell: Just borrowing to try understand their implementation. I wouldn't steal from Microsoft...
@user291320 - depending on which piece of code, the debugging symbols may be free available (under license).
Marc Gravell
@Marc Gravel - I'm trying to understand the HtmlParser class inside the webtestframework.dll. I want to write my own, simple htmlparser. Where would I get the debugging symbols and how would I use them? Can you point me to a link? thanks
A: 

You should look at the HTML Agility Pack.

SLaks