How can we help you today? How can we help you today?

Problem generated code when viewing code in reflector

When viewing a third party DLL in reflector, I get compiler generated code (see below) which I can't decipher. Is there an add-in for reflector or visual studio that can translate this back to normal code; so I can properly debug and rule this section of code out as being the cause of an issue I'm having?
	
	Base.New.Model
	{
		public class StyleHeader : Entity
		{
			private ItemCollection _items;
			
			[NonCacheable]
			public virtual IEnumerable FilteredItems
			{
				get
				{
					<get_FilteredItems>d__0 d__ = new <get_FilteredItems>d__0(-2);
					d__.<>4__this = this;
					return d__;
				}
			}
			
			
		[CompilerGenerated]
        private sealed class <get_FilteredStyleItems>d__0 : IEnumerable<object>, IEnumerable, IEnumerator<object>, IEnumerator, IDisposable
        {
            private int <>1__state;
            private object <>2__current;
            public StyleHeader <>4__this;
            public IEnumerator <>7__wrap2;
            public IDisposable <>7__wrap3;
            public StyleItem <item>5__1;

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

            private bool MoveNext()
            {
                bool flag;
                try
                {
                    switch (this.<>1__state)
                    {
                        case 0:
                            break;

                        case 2:
                            goto Label_0093;

                        default:
                            goto Label_00DC;
                    }
                    this.<>1__state = -1;
                    this.<>7__wrap2 = this.<>4__this.StyleItems.GetEnumerator();
                    this.<>1__state = 1;
                    while (this.<>7__wrap2.MoveNext())
                    {
                        this.<item>5__1 = (StyleItem) this.<>7__wrap2.Current;
                        if (this.<item>5__1.Product.ExcludedFromWeb)
                        {
                            continue;
                        }
                        this.<>2__current = this.<item>5__1;
                        this.<>1__state = 2;
                        return true;
                    Label_0093:
                        this.<>1__state = 1;
                    }
                    this.<>1__state = -1;
                    this.<>7__wrap3 = this.<>7__wrap2 as IDisposable;
                    if (this.<>7__wrap3 != null)
                    {
                        this.<>7__wrap3.Dispose();
                    }
                Label_00DC:
                    flag = false;
                }
                fault
                {
                    ((IDisposable) this).Dispose();
                }
                return flag;
            }

            [DebuggerHidden]
            IEnumerator<object> IEnumerable<object>.GetEnumerator()
            {
                if (Interlocked.CompareExchange(ref this.<>1__state, 0, -2) == -2)
                {
                    return this;
                }
                StyleHeader.<get_FilteredStyleItems>d__0 d__ = new StyleHeader.<get_FilteredStyleItems>d__0(0);
                d__.<>4__this = this.<>4__this;
                return d__;
            }

            [DebuggerHidden]
            IEnumerator IEnumerable.GetEnumerator()
            {
                return this.System.Collections.Generic.IEnumerable<System.Object>.GetEnumerator();
            }

            [DebuggerHidden]
            void IEnumerator.Reset()
            {
                throw new NotSupportedException();
            }

            void IDisposable.Dispose()
            {
                switch (this.<>1__state)
                {
                    case 1:
                    case 2:
                        try
                        {
                        }
                        finally
                        {
                            this.<>1__state = -1;
                            this.<>7__wrap3 = this.<>7__wrap2 as IDisposable;
                            if (this.<>7__wrap3 != null)
                            {
                                this.<>7__wrap3.Dispose();
                            }
                        }
                        break;
                }
            }

            object IEnumerator<object>.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.<>2__current;
                }
            }

            object IEnumerator.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.<>2__current;
                }
            }
        }
	}
:?:
b01
0

Comments

2 comments

  • Clive Tong
    Hi.

    The class you are seeing is generated by the C# compiler for an Enumerator - it generates a state machine which generates items when the MoveNext method is called.

    It seems to be going through the StyleItems and returning those that aren't Product.ExcludedFromWeb.

    We have an outstanding bug report about trying to generate C# code from the state machine, but this is quite complicated. I don't know of any add-ins that will do this.
    Clive Tong
    0
  • b01
    I see. I guess I will have to keep hacking away. Thanks for the quick response.
    b01
    0

Add comment

Please sign in to leave a comment.