|
1 |
| -usingSystem; |
2 |
| -usingSystem.Collections.Generic; |
3 |
| -usingSystem.Collections; |
4 |
| - |
5 |
| -namespacePython.Runtime.CollectionWrappers |
6 |
| -{ |
7 |
| -internalclassIterableWrapper<T>:IEnumerable<T> |
8 |
| -{ |
9 |
| -protectedreadonlyPyObjectpyObject; |
10 |
| - |
11 |
| -publicIterableWrapper(PyObjectpyObj) |
12 |
| -{ |
13 |
| -if(pyObj==null) |
14 |
| -thrownewArgumentNullException(); |
15 |
| -pyObject=newPyObject(pyObj.Reference); |
16 |
| -} |
17 |
| - |
18 |
| -IEnumeratorIEnumerable.GetEnumerator()=>GetEnumerator(); |
19 |
| - |
20 |
| -publicIEnumerator<T>GetEnumerator() |
21 |
| -{ |
22 |
| -PyIteriterObject; |
23 |
| -using(Py.GIL()) |
24 |
| -{ |
25 |
| -iterObject=PyIter.GetIter(pyObject); |
| 1 | +usingSystem; |
| 2 | +usingSystem.Collections.Generic; |
| 3 | +usingSystem.Collections; |
| 4 | + |
| 5 | +namespacePython.Runtime.CollectionWrappers |
| 6 | +{ |
| 7 | +internalclassIterableWrapper<T>:IEnumerable<T> |
| 8 | +{ |
| 9 | +protectedreadonlyPyObjectpyObject; |
| 10 | + |
| 11 | +publicIterableWrapper(PyObjectpyObj) |
| 12 | +{ |
| 13 | +if(pyObj==null) |
| 14 | +thrownewArgumentNullException(); |
| 15 | +pyObject=newPyObject(pyObj.Reference); |
| 16 | +} |
| 17 | + |
| 18 | +IEnumeratorIEnumerable.GetEnumerator()=>GetEnumerator(); |
| 19 | + |
| 20 | +publicIEnumerator<T>GetEnumerator() |
| 21 | +{ |
| 22 | +PyIteriterObject; |
| 23 | +using(Py.GIL()) |
| 24 | +{ |
| 25 | +iterObject=PyIter.GetIter(pyObject); |
26 | 26 | }
|
27 |
| - |
28 |
| -usingvar_=iterObject; |
29 |
| -while(true) |
| 27 | +try |
30 | 28 | {
|
31 |
| -usingvarGIL=Py.GIL(); |
32 |
| - |
33 |
| -if(!iterObject.MoveNext()) |
| 29 | +while(true) |
34 | 30 | {
|
35 |
| -iterObject.Dispose(); |
36 |
| -break; |
| 31 | +usingvar_=Py.GIL(); |
| 32 | +if(!iterObject.MoveNext()) |
| 33 | +{ |
| 34 | +break; |
| 35 | +} |
| 36 | +yieldreturniterObject.Current.As<T>()!; |
37 | 37 | }
|
38 |
| -yieldreturniterObject.Current.As<T>()!; |
39 | 38 | }
|
40 |
| -} |
41 |
| -} |
42 |
| -} |
| 39 | +finally |
| 40 | +{ |
| 41 | +usingvar_=Py.GIL(); |
| 42 | +iterObject.Dispose(); |
| 43 | +} |
| 44 | +} |
| 45 | +} |
| 46 | +} |