Ejemplo n.º 1
0
 public static PyObject ManagedObjectToPython(object obj, Type pyType)
 {
     if (obj is string || obj is int || obj is float || obj is null)
     {
         return(obj.ToPython());
     }
     else if (typeof(IList).IsAssignableFrom(pyType))
     {
         PyList list = new PyList();
         for (int i = 0; i < (obj as IList).Count; i++)
         {
             if (!(obj as IList)[i].GetType().IsPrimitive)
             {
                 continue;
             }
             list.SetItem(i, (obj as IList)[i].ToPython());
         }
         return(list);
     }
     else if (typeof(IDictionary).IsAssignableFrom(pyType))
     {
         PyDict dict = new PyDict();
         foreach (DictionaryEntry kv in (obj as IDictionary))
         {
             if (!kv.Value.GetType().IsPrimitive)
             {
                 continue;
             }
             dict.SetItem(kv.Key.ToPython(), kv.Value.ToPython());
         }
         return(dict);
     }
     else
     {
         throw new NotSupportedException("Unsupported type: " + obj.GetType().Name);
     }
 }