20 using System.Collections.Generic;
29 private readonly
Slice _slice;
30 private static readonly PyObject _converter;
37 _converter = PyModule.FromString(
"converter",
38 "class Data(object):\n" +
39 " def __init__(self, data):\n" +
40 " self.data = data\n" +
41 " members = [attr for attr in dir(data) if not callable(attr) and not attr.startswith(\"__\")]\n" +
42 " for member in members:\n" +
43 " setattr(self, member, getattr(data, member))\n" +
44 " for kvp in data.GetStorageDictionary():\n" +
45 " name = kvp.Key.replace('-',' ').replace('.',' ').title().replace(' ', '')\n" +
46 " value = kvp.Value if isinstance(kvp.Value, float) else kvp.Value\n" +
47 " setattr(self, name, value)\n" +
49 " def __str__(self):\n" +
50 " return self.data.ToString()");
72 return GetImpl(type.CreateType(), _slice)[symbol];
80 public PyObject
Get(PyObject type)
82 var result =
GetImpl(type.CreateType(), _slice) as object;
85 return result.ToPython();
92 public override int Count
94 get {
return _slice.Count; }
100 public override IReadOnlyList<Symbol>
Keys
102 get {
return _slice.Keys; }
108 public override IReadOnlyList<BaseData>
Values
110 get {
return _slice.Values; }
121 public override dynamic
this[
Symbol symbol]
125 var data = _slice[symbol];
128 if (dynamicData !=
null)
134 return _converter.InvokeMethod(
"Data",
new[] { dynamicData.ToPython() });
153 return _slice.ContainsKey(symbol);
164 return _slice.TryGetValue(symbol, out data);