예제 #1
0
        public static bool TryCreate(object baseObject, out IEnumerator enumerator)
        {
            if (TryCastIEnumer(baseObject, out enumerator))
            {
                return(true);
            }

            object iter;

            if (PythonOps.TryGetBoundAttr(baseObject, "__iter__", out iter))
            {
                object iterator = PythonCalls.Call(iter);
                // don't re-wrap if we don't need to (common case is PythonGenerator).
                if (TryCastIEnumer(iterator, out enumerator))
                {
                    return(true);
                }
                enumerator = new PythonEnumerator(iterator);
                return(true);
            }
            else
            {
                enumerator = null;
                return(false);
            }
        }
예제 #2
0
        public static bool Create(object baseEnumerator, out IEnumerator enumerator)
        {
            object iter;

            if (Ops.TryGetAttr(baseEnumerator, SymbolTable.Iterator, out iter))
            {
                object iterator = Ops.Call(iter);
                enumerator = new PythonEnumerator(iterator);
                return(true);
            }
            else
            {
                enumerator = null;
                return(false);
            }
        }
예제 #3
0
        public static bool TryCreate(object baseEnumerator, out IEnumerator enumerator)
        {
            object iter;

            if (Ops.TryGetAttr(baseEnumerator, SymbolTable.Iterator, out iter)) {
                object iterator = Ops.Call(iter);
                enumerator = new PythonEnumerator(iterator);
                return true;
            } else {
                enumerator = null;
                return false;
            }
        }