Beispiel #1
0
        public async Tasks.Task <bool> Write(Generic.IEnumerator <byte> buffer)
        {
            bool result = buffer.NotNull();

            if (result)
            {
                int seek = this.peeked.Reset();
                if (seek != 0)
                {
                    await this.Seek(seek);
                }
                try
                {
                    byte[] array = buffer.ToArray();
                    await this.backend.WriteAsync(array, 0, array.Length);

                    if (this.AutoFlush)
                    {
                        await this.Flush();
                    }
                }
                catch (System.Exception)
                {
                    result = false;
                }
            }
            return(result);
        }
Beispiel #2
0
 public static Generic.IEnumerator <TResult> Zip <TLeft, TRight, TResult>(this Generic.IEnumerator <TLeft> me, Generic.IEnumerator <TRight> other, Func <TLeft, TRight, TResult> combine)
 {
     if (me.NotNull() && other.NotNull() && combine.NotNull())
     {
         while (me.MoveNext() && other.MoveNext())
         {
             yield return(combine(me.Current, other.Current));
         }
     }
 }
Beispiel #3
0
 public static IList <T> Add <T>(this IList <T> me, Generic.IEnumerator <T> items)
 {
     if (items.NotNull())
     {
         while (items.MoveNext())
         {
             me.Add(items.Current);
         }
     }
     return(me);
 }
Beispiel #4
0
        public static T First <T>(this Generic.IEnumerator <T> me)
        {
            T result;

            if (me.NotNull())
            {
                result = me.MoveNext() ? me.Current : default(T);
                me.Dispose();
            }
            else
            {
                result = default(T);
            }
            return(result);
        }
Beispiel #5
0
 public static Generic.IEnumerator <T> Append <T>(this Generic.IEnumerator <T> me, Generic.IEnumerator <T> other)
 {
     if (me.NotNull())
     {
         while (me.MoveNext())
         {
             yield return(me.Current);
         }
     }
     if (other.NotNull())
     {
         while (other.MoveNext())
         {
             yield return(other.Current);
         }
     }
 }
Beispiel #6
0
 public static IAsyncEnumerator <T> Create <T>(Generic.IEnumerator <T> enumerator)
 {
     return(enumerator.NotNull() ? AsyncEnumerator.Create(() => Tasks.Task.FromResult(enumerator.Next()), enumerator) : AsyncEnumerator.Empty <T>());
 }
Beispiel #7
0
 public static bool SameOrEquals <T>(this Generic.IEnumerator <T> me, Generic.IEnumerator <T> other)
 {
     return(me.IsNull() && other.IsNull() ||
            me.NotNull() && other.NotNull() && (me.MoveNext() ? other.MoveNext() && me.Current.SameOrEquals(other.Current) && me.SameOrEquals(other) : !other.MoveNext()));
 }
Beispiel #8
0
 public static T[] ToArray <T>(this Generic.IEnumerator <T> me)
 {
     return(me.NotNull() ? me.ToArray(0) : null);
 }
Beispiel #9
0
 public static T Next <T>(this Generic.IEnumerator <T> me, T @default = default(T))
 {
     return(me.NotNull() && me.MoveNext() ? me.Current : @default);
 }
Beispiel #10
0
 public static Generic.IEnumerator <T> Create <T>(Generic.IEnumerator <T> enumerator)
 {
     return(enumerator.NotNull() ? Enumerator.Create(() => enumerator.Next(), enumerator.Reset, enumerator.Dispose) : Enumerator.Empty <T>());
 }