See More

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(); } }