本文整理汇总了C#中PyObject.GetPyType方法的典型用法代码示例。如果您正苦于以下问题:C# PyObject.GetPyType方法的具体用法?C# PyObject.GetPyType怎么用?C# PyObject.GetPyType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyObject
的用法示例。
在下文中一共展示了PyObject.GetPyType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: 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;
}
示例3: GetPyValue
private string GetPyValue(PyObject attr)
{
switch (attr.GetPyType())
{
case PyType.FloatType:
case PyType.DerivedFloatType:
return ((double) attr).ToString();
case PyType.IntType:
case PyType.LongType:
case PyType.DerivedIntType:
case PyType.DerivedLongType:
return ((long) attr).ToString();
case PyType.BoolType:
case PyType.DerivedBoolType:
return ((bool) attr).ToString();
case PyType.StringType:
case PyType.UnicodeType:
case PyType.DerivedStringType:
case PyType.DerivedUnicodeType:
return (string) attr;
case PyType.MethodType:
var x = attr.Attribute("im_func").Attribute("func_code");
var name = (string) x.Attribute("co_name");
var argCount = (int) x.Attribute("co_argcount");
var args = string.Join(",", x.Attribute("co_varnames").ToList<string>().Take(argCount).ToArray());
return name + "(" + args + ")";
default:
return attr.ToString();
}
}