[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/pythonnet/pythonnet/v3.1.0/src/runtime/PythonTypes/PyIterable.cs [Back]  [Original]

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Python.Runtime
{
    [Serializable]
    public class PyIterable : PyObject, IEnumerable
    {
        internal PyIterable(BorrowedReference reference) : base(reference) { }
        internal PyIterable(in StolenReference reference) : base(reference) { }
        protected PyIterable(SerializationInfo info, StreamingContext context)
            : base(info, context) { }

        /// 
        /// Creates new instance from an existing object.
        /// 
        /// This constructor does not check if  is actually iterable.
        public PyIterable(PyObject o) : base(FromObject(o)) { }

        static BorrowedReference FromObject(PyObject o)
        {
            if (o is null) throw new ArgumentNullException(nameof(o));
            return o.Reference;
        }

        /// 
        /// Return a new PyIter object for the object. This allows any iterable
        /// python object to be iterated over in C#. A PythonException will be
        /// raised if the object is not iterable.
        /// 
        public PyIter GetEnumerator()
        {
            return PyIter.GetIter(this);
        }
        IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
        IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
    }
}

Web Proxy Viewer  |  New URL  |  Original Page