コード例 #1
0
        /// <summary>
        ///     Clear this PyObject (the PyObject must be a List or Dictionary)
        /// </summary>
        /// <param name="pyType">Force this Python Type</param>
        /// <returns></returns>
        /// <remarks>
        ///     For a list attribute, the list is cleared
        ///     For a Dictionary attribute, the dictionary is cleared
        /// </remarks>
        public bool Clear(PyType pyType)
        {
            try
            {
                switch (pyType)
                {
                case PyType.ListType:
                case PyType.DerivedListType:
                    return(Py.PyList_SetSlice(this, 0, Size() - 1, PySharp.PyZero) == 0);

                case PyType.DictType:
                case PyType.DictProxyType:
                case PyType.DerivedDictType:
                case PyType.DerivedDictProxyType:
                    return(ToDictionary().All(item => Py.PyDict_DelItem(this, item.Key) == 0));
                }

                return(false);
            }
            finally
            {
                HandlePythonError();
            }
        }