Exemplo n.º 1
0
        private void ListPyObject(PyObject pyObject)
        {
            PyType type;

            switch (_typeMode)
            {
            case TypeMode.Value:
                // Fill the value here
                var value = new PyValue();
                value.Attribute = "(this)";
                value.Value     = GetPyValue(pyObject);
                value.Type      = pyObject.GetPyType().ToString();
                _values.Add(value);
                return;

            case TypeMode.Class:
                // Force it to unknown
                type = PyType.Unknown;
                break;

            case TypeMode.List:
                // Force it to a list
                type = PyType.ListType;
                break;

            case TypeMode.Tuple:
                // Force it to a tuple
                type = PyType.TupleType;
                break;

            case TypeMode.Dictionary:
                // Force it to a dictionary
                type = PyType.DictType;
                break;

            default:
                // Let the type decide
                type = pyObject.GetPyType();
                break;
            }

            switch (type)
            {
            case PyType.DictType:
            case PyType.DictProxyType:
            case PyType.DerivedDictType:
            case PyType.DerivedDictProxyType:
                foreach (var attribute in pyObject.ToDictionary())
                {
                    var item = new PyValue();
                    item.Attribute = GetPyValue(attribute.Key);
                    item.Value     = GetPyValue(attribute.Value);
                    item.Type      = attribute.Value.GetPyType().ToString();
                    item.Eval      = _evaluate + "[" + item.Attribute + "]";
                    _values.Add(item);
                }
                break;

            case PyType.ListType:
            case PyType.TupleType:
            case PyType.DerivedListType:
            case PyType.DerivedTupleType:
                var length = pyObject.Size(type);
                for (var i = 0; i < length; i++)
                {
                    var item = new PyValue();
                    item.Attribute = i.ToString();
                    item.Value     = GetPyValue(pyObject.Item(i, type));
                    item.Type      = pyObject.Item(i, type).GetPyType().ToString();
                    item.Eval      = _evaluate + "[" + i + "]";
                    _values.Add(item);
                }
                break;

            default:
                foreach (var attribute in pyObject.Attributes())
                {
                    var item = new PyValue();
                    item.Attribute = attribute.Key;
                    item.Value     = GetPyValue(attribute.Value);
                    item.Type      = attribute.Value.GetPyType().ToString();
                    item.Eval      = _evaluate + "." + attribute.Key;
                    _values.Add(item);
                }
                break;
            }
        }
Exemplo n.º 2
0
        private void ListPyObject(PyObject pyObject)
        {
            PyType type;
            switch (_typeMode)
            {
                case TypeMode.Value:
                    // Fill the value here
                    var value = new PyValue();
                    value.Attribute = "(this)";
                    value.Value = GetPyValue(pyObject);
                    value.Type = pyObject.GetPyType().ToString();
                    _values.Add(value);
                    return;

                case TypeMode.Class:
                    // Force it to unknown
                    type = PyType.Unknown;
                    break;

                case TypeMode.List:
                    // Force it to a list
                    type = PyType.ListType;
                    break;

                case TypeMode.Tuple:
                    // Force it to a tuple
                    type = PyType.TupleType;
                    break;

                case TypeMode.Dictionary:
                    // Force it to a dictionary
                    type = PyType.DictType;
                    break;

                default:
                    // Let the type decide
                    type = pyObject.GetPyType();
                    break;
            }

            switch (type)
            {
                case PyType.DictType:
                case PyType.DictProxyType:
                case PyType.DerivedDictType:
                case PyType.DerivedDictProxyType:
                    foreach (var attribute in pyObject.ToDictionary())
                    {
                        var item = new PyValue();
                        item.Attribute = GetPyValue(attribute.Key);
                        item.Value = GetPyValue(attribute.Value);
                        item.Type = attribute.Value.GetPyType().ToString();
                        item.Eval = _evaluate + "[" + item.Attribute + "]";
                        _values.Add(item);
                    }
                    break;

                case PyType.ListType:
                case PyType.TupleType:
                case PyType.DerivedListType:
                case PyType.DerivedTupleType:
                    var length = pyObject.Size(type);
                    for (var i = 0; i < length; i++)
                    {
                        var item = new PyValue();
                        item.Attribute = i.ToString();
                        item.Value = GetPyValue(pyObject.Item(i, type));
                        item.Type = pyObject.Item(i, type).GetPyType().ToString();
                        item.Eval = _evaluate + "[" + i + "]";
                        _values.Add(item);
                    }
                    break;

                default:
                    foreach (var attribute in pyObject.Attributes())
                    {
                        var item = new PyValue();
                        item.Attribute = attribute.Key;
                        item.Value = GetPyValue(attribute.Value);
                        item.Type = attribute.Value.GetPyType().ToString();
                        item.Eval = _evaluate + "." + attribute.Key;
                        _values.Add(item);
                    }
                    break;
            }
        }