当前位置: 首页>>代码示例>>C#>>正文


C# PyObject.ToDictionary方法代码示例

本文整理汇总了C#中PyObject.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# PyObject.ToDictionary方法的具体用法?C# PyObject.ToDictionary怎么用?C# PyObject.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyObject的用法示例。


在下文中一共展示了PyObject.ToDictionary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Evaluate

        private PyObject Evaluate(PySharp.PySharp pySharp, PyObject pyObject)
        {
            // TODO: Better part splitting (e.g. bla('bla', const.bla)
            var parts = _evaluate.Split('.');
            if (parts.Length == 0)
            {
                // TODO: List imports
                return null;
            }

            if (pyObject == null)
                pyObject = pySharp.Import(parts[0]);

            for (var i = 1; i < parts.Length; i++)
            {
                if (parts[i].Contains("("))
                {
                    // TODO: Call
                }
                else if (parts[i].Contains("["))
                {
                    var attr = parts[i].Substring(0, parts[i].IndexOf('['));

                    var key = parts[i].Substring(parts[i].IndexOf('[') + 1, parts[i].IndexOf(']') - parts[i].IndexOf('[') - 1);
                    if (key.StartsWith("'") || key.StartsWith("\""))
                        key = key.Substring(1, key.Length - 2);

                    if (!string.IsNullOrEmpty(attr))
                        pyObject = pyObject.Attribute(attr);

                    if (pyObject.GetPyType() == PyType.DictType ||
                        pyObject.GetPyType() == PyType.DerivedDictType ||
                        pyObject.GetPyType() == PyType.DictProxyType ||
                        pyObject.GetPyType() == PyType.DerivedDictProxyType)
                    {
                        var dict = pyObject.ToDictionary();

                        pyObject = PySharp.PySharp.PyZero;
                        foreach (var dictItem in dict)
                        {
                            if (GetPyValue(dictItem.Key) == key)
                                pyObject = dictItem.Value;
                        }
                    }
                    else
                    {
                        int index;
                        pyObject = int.TryParse(key, out index) ? pyObject.Item(index) : PySharp.PySharp.PyZero;
                    }
                }
                else
                {
                    pyObject = pyObject.Attribute(parts[i]);
                }
            }

            return pyObject;
        }
开发者ID:Blinker,项目名称:DirectEve,代码行数:58,代码来源:frmMain.cs

示例2: ListPyObject

        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;
            }
        }
开发者ID:Blinker,项目名称:DirectEve,代码行数:86,代码来源:frmMain.cs


注:本文中的PyObject.ToDictionary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。