奇怪的反射器反编译并出现无效令牌错误

发布于 2024-09-15 19:07:44 字数 3273 浏览 4 评论 0原文

有好心人能帮我整理一下.Net Reflector v6.5 无法编译的输出吗?我认为这些符号不正常,但全局搜索和替换可能会解决这个问题。我不明白奇怪的类定义。有想法吗?

    [CompilerGenerated]
    private sealed class <ApplicationTaskIterator>d__0 : IEnumerable<ApplicationTask>, IEnumerable, IEnumerator<ApplicationTask>, IEnumerator, IDisposable
    {
        private int <>1__state;
        private ApplicationTask <>2__current;
        public SessionMetrics <>3__sm;
        public Dictionary<int, ThreadMetrics> <>7__wrap3;
        public Dictionary<int, ThreadMetrics>.ValueCollection.Enumerator <>7__wrap4;
        public ApplicationTask <currentTask>5__1;
        public ThreadMetrics <tm>5__2;
        public SessionMetrics sm;

        [DebuggerHidden]
        public <ApplicationTaskIterator>d__0(int <>1__state)
        {
            this.<>1__state = <>1__state;
        }

        private bool MoveNext()
        {
            try
            {
                switch (this.<>1__state)
                {
                    case 0:
                        this.<>1__state = -1;
                        Monitor.Enter(this.<>7__wrap3 = ThreadMetrics._allThreadMetrics);
                        this.<>1__state = 1;
                        this.<>7__wrap4 = ThreadMetrics._allThreadMetrics.Values.GetEnumerator();
                        this.<>1__state = 2;
                        while (this.<>7__wrap4.MoveNext())
                        {
                            this.<tm>5__2 = this.<>7__wrap4.Current;
                            if ((((this.<tm>5__2._managedThread.ThreadState == System.Threading.ThreadState.Stopped) || object.ReferenceEquals(this.<tm>5__2._managedThread, Thread.CurrentThread)) || ((this.<currentTask>5__1 = this.<tm>5__2.CurrentApplicationTask) == null)) || ((this.sm != null) && !this.<currentTask>5__1.CurrentSessionMetrics.SessionGUID.Equals(this.sm.SessionGUID)))
                            {
                                continue;
                            }
                            this.<currentTask>5__1.Active = !this.<tm>5__2.Suspended;
                            this.<>2__current = this.<currentTask>5__1;
                            this.<>1__state = 3;
                            return true;
                        Label_010C:
                            this.<>1__state = 2;
                        }
                        this.<>1__state = 1;
                        this.<>7__wrap4.Dispose();
                        this.<>1__state = -1;
                        Monitor.Exit(this.<>7__wrap3);
                        break;

                    case 3:
                        goto Label_010C;
                }
                return false;
            }
            fault
            {
                ((IDisposable) this).Dispose();
            }
        }
    }

像这样使用:

    internal static IEnumerable<ApplicationTask> ApplicationTaskIterator(SessionMetrics sm)
    {
        return new <ApplicationTaskIterator>d__0(-2) { <>3__sm = sm };
    }

Would some kind person help me sort out the output of .Net Reflector v6.5 that does not compile? I think that the symbols are out of whack but global search and replace might fix that. I don't get the odd class definition. Ideas?

    [CompilerGenerated]
    private sealed class <ApplicationTaskIterator>d__0 : IEnumerable<ApplicationTask>, IEnumerable, IEnumerator<ApplicationTask>, IEnumerator, IDisposable
    {
        private int <>1__state;
        private ApplicationTask <>2__current;
        public SessionMetrics <>3__sm;
        public Dictionary<int, ThreadMetrics> <>7__wrap3;
        public Dictionary<int, ThreadMetrics>.ValueCollection.Enumerator <>7__wrap4;
        public ApplicationTask <currentTask>5__1;
        public ThreadMetrics <tm>5__2;
        public SessionMetrics sm;

        [DebuggerHidden]
        public <ApplicationTaskIterator>d__0(int <>1__state)
        {
            this.<>1__state = <>1__state;
        }

        private bool MoveNext()
        {
            try
            {
                switch (this.<>1__state)
                {
                    case 0:
                        this.<>1__state = -1;
                        Monitor.Enter(this.<>7__wrap3 = ThreadMetrics._allThreadMetrics);
                        this.<>1__state = 1;
                        this.<>7__wrap4 = ThreadMetrics._allThreadMetrics.Values.GetEnumerator();
                        this.<>1__state = 2;
                        while (this.<>7__wrap4.MoveNext())
                        {
                            this.<tm>5__2 = this.<>7__wrap4.Current;
                            if ((((this.<tm>5__2._managedThread.ThreadState == System.Threading.ThreadState.Stopped) || object.ReferenceEquals(this.<tm>5__2._managedThread, Thread.CurrentThread)) || ((this.<currentTask>5__1 = this.<tm>5__2.CurrentApplicationTask) == null)) || ((this.sm != null) && !this.<currentTask>5__1.CurrentSessionMetrics.SessionGUID.Equals(this.sm.SessionGUID)))
                            {
                                continue;
                            }
                            this.<currentTask>5__1.Active = !this.<tm>5__2.Suspended;
                            this.<>2__current = this.<currentTask>5__1;
                            this.<>1__state = 3;
                            return true;
                        Label_010C:
                            this.<>1__state = 2;
                        }
                        this.<>1__state = 1;
                        this.<>7__wrap4.Dispose();
                        this.<>1__state = -1;
                        Monitor.Exit(this.<>7__wrap3);
                        break;

                    case 3:
                        goto Label_010C;
                }
                return false;
            }
            fault
            {
                ((IDisposable) this).Dispose();
            }
        }
    }

Used like this:

    internal static IEnumerable<ApplicationTask> ApplicationTaskIterator(SessionMetrics sm)
    {
        return new <ApplicationTaskIterator>d__0(-2) { <>3__sm = sm };
    }

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

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

发布评论

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

评论(1

回首观望 2024-09-22 19:07:44

这就是 C# 编译器将包含 yield return 语句的方法转换为的内容。

如果您想让代码编译,您可以尝试破译该方法正在做什么,并使用 yield return 语句重新创建原始版本;或者您可以将类和所有成员重命名为有效的 C# 名称。


原来的方法大概是这样的:

internal static IEnumerable<ApplicationTask> ApplicationTaskIterator(SessionMetrics sm)
{
    lock (ThreadMetrics._allThreadMetrics)
    {
        foreach (var tm in ThreadMetrics._allThreadMetrics.Values)
        {
            if (tm._managedThread.ThreadState != ThreadState.Stopped)
            {
                if (!object.ReferenceEquals(tm._managedThread, Thread.CurrentThread))
                {
                    ApplicationTask currentTask;
                    if ((currentTask = tm.CurrentApplicationTask) != null)
                    {
                        if (sm == null || !currentTask.CurrentSessionMetrics.SessionGUID.Equals(sm.SessionGUID))
                        {
                            currentTask.Active = !tm.Suspended;
                            yield return currentTask;
                        }
                    }
                }
            }
        }
    }
}

That's simply what the C# compiler transforms a method containing yield return statements to.

If you want to make the code compile, you can either try to decipher what the method is doing and recreate the original version with yield return statements; or you can rename the class and all members to valid C# names.


The original method probably looked like this:

internal static IEnumerable<ApplicationTask> ApplicationTaskIterator(SessionMetrics sm)
{
    lock (ThreadMetrics._allThreadMetrics)
    {
        foreach (var tm in ThreadMetrics._allThreadMetrics.Values)
        {
            if (tm._managedThread.ThreadState != ThreadState.Stopped)
            {
                if (!object.ReferenceEquals(tm._managedThread, Thread.CurrentThread))
                {
                    ApplicationTask currentTask;
                    if ((currentTask = tm.CurrentApplicationTask) != null)
                    {
                        if (sm == null || !currentTask.CurrentSessionMetrics.SessionGUID.Equals(sm.SessionGUID))
                        {
                            currentTask.Active = !tm.Suspended;
                            yield return currentTask;
                        }
                    }
                }
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文