反射器和编译器生成的代码

发布于 2024-08-29 22:04:36 字数 661 浏览 1 评论 0原文

我有一个 dll,我在 Reflector 中反汇编它,然后生成一个类。 该类包含无法在 Visual Studio 中编译的代码。

我认为它是 leagl IL 代码,但如何从中生成更高级别的 c# 代码。

似乎yield 和 IEnumerator 在 IL 中生成诸如 <>1__state; 之类的东西,但无法编译。

有谁知道我如何从包含此类 IL 的反射器生成一个类?

有没有反射器插件可以解决这个问题?

    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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花之痕靓丽 2024-09-05 22:04:36

该 IL 来自迭代器块。手动编写迭代器可怕,而迭代器块中的底层 IL 证明了编译器为您所做的事情的真实性。 庆幸您不必自己做!

您可以尝试主要通过MoveNext()将它们组合在一起,但不要指望奇迹。您可能还会发现重命名字段(以消除诸如 <> 前缀之类的内容)会大有帮助。

然而;我期望最好的办法是理解代码想要做什么,并停止尝试简单地窃取借用< /em> 他们的实现。

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.

心病无药医 2024-09-05 22:04:36

您应该查看 HTML Agility Pack

You should look at the HTML Agility Pack.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文