[pypy-dev] mapping C# iterator to Python iterator

amit regmi.amit at gmail.com
Sun Dec 2 01:50:57 CET 2007


Taking example of System.Collection.ArrayList  class.

If the class uses the interface IEnumerable that can be checked using 
reflection  

    b_type = System.Type.GetType(fullname)
    ifaces = b_type.GetInterfaces()
    for interface in ifaces:
    if interface =="IEnumerable":
            print "yes"

Problems mapping the two functions
    d['__iter__'] = d['GetEnumerator']
    d['next'] = d['MoveNext']

to make C# objects iterable in PyPy-Cli module.

a) MoveNext() is not available in both "methods" and "staticmethods" 
passed to build_wrapper
b) and assignment of GetEnumerator to __iter__ gives following TypeError.
    TypeError: Can't convert object 
System.Collections.ArrayList+SimpleEnumerator to Python


I had in mind something like
    
    class Dummy:
    __iter__(self):
       return CS.Current()

    next(self):
       bool = CS.MoveNext()
       if bool == false:
        raise StopIteration

any thoughts ?

-AmitReg



More information about the Pypy-dev mailing list