带有无效令牌错误的奇数反射器反编译

时间:2010-08-20 14:38:31

标签: c# .net reflector .net-reflector

有些人会帮我理清不编译的.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 };
    }

1 个答案:

答案 0 :(得分:1)

这就是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;
                        }
                    }
                }
            }
        }
    }
}