public bool MoveNext()
                {
                    switch (state)
                    {
                    case EnumeratorState.Enumerating:
                        if (++sourceIndex >= end)
                        {
                            state = EnumeratorState.Complete;
                            return(false);
                        }

                        var enumerable = selector.Invoke(source[sourceIndex]);
                        subEnumerator = enumerable.GetEnumerator();

                        state = EnumeratorState.EnumeratingSub;
                        goto case EnumeratorState.EnumeratingSub;

                    case EnumeratorState.EnumeratingSub:
                        if (!subEnumerator.MoveNext())
                        {
                            state = EnumeratorState.Enumerating;
                            goto case EnumeratorState.Enumerating;
                        }
                        return(true);

                    default:
                        return(false);
                    }
                }
Beispiel #2
0
 public bool MoveNext()
 {
     if (first)
     {
         first = false;
         while (enumerator.MoveNext())
         {
             sub = mapper(enumerator.Current).GetEnumerator();
             if (sub.MoveNext())
             {
                 return(true);
             }
         }
         return(false);
     }
     else
     {
         if (!sub.MoveNext())
         {
             while (enumerator.MoveNext())
             {
                 sub = mapper(enumerator.Current).GetEnumerator();
                 if (sub.MoveNext())
                 {
                     return(true);
                 }
             }
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }