public static PyListIterator Create(PyList list) { var iterator = PyTypeObject.DefaultNew <PyListIterator>(PyListIteratorClass.Instance); iterator.CurrentIdx = 0; iterator.IteratedList = list; return(iterator); }
public static PyBool __contains__(PyList self, PyObject v) { if (self.list.Contains(v)) { return(PyBool.True); } else { return(PyBool.False); } }
// TODO: Manage slices public static void __setitem__(PyList self, int i, PyObject value) { try { self.list[i] = value; } catch (IndexOutOfRangeException) { // TODO: Represent as a more natural Python exception; throw new Exception("IndexError: list assignment index out of range"); } }
public static object __getitem__(PyList self, PyInteger i) { try { return(self.list[(int)i.InternalValue]); } catch (IndexOutOfRangeException) { // TODO: Represent as a more natural Python exception; throw new Exception("IndexError: list index out of range"); } }
public static void __delitem__(PyList self, PyInteger i) { try { self.list.RemoveAt((int)i.InternalValue); } catch (IndexOutOfRangeException) { // TODO: Represent as a more natural Python exception; throw new Exception("IndexError: list assignment index out of range"); } }
public static PyBool __eq__(PyList self, PyObject other) { var otherList = other as PyList; if (otherList == null) { return(PyBool.False); } if (otherList.list.Count != self.list.Count) { return(PyBool.False); } for (int i = 0; i < self.list.Count; ++i) { if (self.list[i].__eq__(otherList.list[i]).boolean == false) { return(PyBool.False); } } return(PyBool.True); }
public static PyBool __eq__(PyList self, object other) { var otherList = other as PyList; if (otherList == null) { return(PyBool.False); } if (otherList.list.Count != self.list.Count) { return(PyBool.False); } for (int i = 0; i < self.list.Count; ++i) { var selfPyObject = self.list[i] as PyObject; var otherPyObject = otherList.list[i] as PyObject; if (selfPyObject == null || otherPyObject == null) { return(PyBool.False); } else if (selfPyObject != null) { if (selfPyObject.__eq__(otherPyObject).InternalValue == false) { return(PyBool.False); } } else if (!self.list[i].Equals(otherList.list[i])) { return(PyBool.False); } } return(PyBool.True); }
public static void __setitem__(PyList self, PyInteger i, PyObject value) { __setitem__(self, (int)i.InternalValue, value); }
public static void prepend(PyList self, PyObject toAdd) { self.list.Insert(0, toAdd); }
public static void append(PyList self, PyObject toAdd) { self.list.Add(toAdd); }
public static void clear(PyList self) { self.list.Clear(); }
public static PyBool __ne__(PyList self, PyObject other) { return(!__eq__(self, other)); }