public void WriteObject(object o) { List <object> infinite = PythonOps.GetReprInfinite(); if (infinite.Contains(o)) { throw PythonOps.ValueError("Marshaled data contains infinite cycle"); } int index = infinite.Count; infinite.Add(o); try { if (o == null) { _bytes.Add((byte)'N'); } else if (o == ScriptingRuntimeHelpers.True || (o is bool && (bool)o)) { _bytes.Add((byte)'T'); } else if (o == ScriptingRuntimeHelpers.False || (o is bool && (!(bool)o))) { _bytes.Add((byte)'F'); } else if (o is IList <byte> ) { WriteBytes(o as IList <byte>); } else if (o is string) { WriteString(o as string); } else if (o is int) { WriteInt((int)o); } else if (o is float) { WriteFloat((float)o); } else if (o is double) { WriteFloat((double)o); } else if (o is long) { WriteLong((long)o); } else if (o.GetType() == typeof(PythonList)) { WriteList(o); } else if (o.GetType() == typeof(PythonDictionary)) { WriteDict(o); } else if (o.GetType() == typeof(PythonTuple)) { WriteTuple(o); } else if (o.GetType() == typeof(SetCollection)) { WriteSet(o); } else if (o.GetType() == typeof(FrozenSetCollection)) { WriteFrozenSet(o); } else if (o is BigInteger) { WriteInteger((BigInteger)o); } else if (o is Complex) { WriteComplex((Complex)o); } else if (o == PythonExceptions.StopIteration) { WriteStopIteration(); } else { throw PythonOps.ValueError("unmarshallable object" + o.GetType().ToString()); } } finally { infinite.RemoveAt(index); } }