To map these to .NET's IEnumerator/IEnumerable you just need to define __iter__ or __getitem__. If you define __iter__ you should return something that is enumerable (implements IEnumerable or has a next method which we'll call until it throws to stop enumeration). If you define __getitem__ we'll try and index from 0 to infinity and stop at an index out of range or stop iteration exception.
You explicitly mention "say for ArrayList object" and I'm not sure what that means - we won't convert an arbitrary enumerable into another type such as ArrayList. But we will convert it one of the enumeration interfaces. When we pass your object out it'll be wrapped in one of our PythonEnumerable/PythonEnumerator/ItemEnumerable/ItemEnumerator classes. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of amit Sent: Saturday, December 01, 2007 4:15 PM To: [email protected] Subject: [IronPython] mapping C# iterators to Python iterator Hi, I want to know how the "Iterators" in C# can be mapped to those in Python. What I tried was: say for ArrayList object def __iter__(self): self.index = self.Count return self def next(self): if self.index == 0: raise StopIteration self.index = self.index - 1 return ?? If I am creating python classes dynamically how would I map GetEnumerator() , MoveNext() , Current() , Reset() to python Class so as to make it iterable inside python. --Regmee _______________________________________________ Users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
