protected void MarshalTop(object obj, WriteCache cache) { IWriteHandler handler = GetHandler(obj); if (handler == null) { throw new NotSupportedException( string.Format("Cannot marshal type {0} ({1})", obj != null ? obj.GetType() : null, obj)); } string tag = handler.Tag(obj); if (tag == null) { throw new NotSupportedException( string.Format("Cannot marshal type {0} ({1})", obj != null ? obj.GetType() : null, obj)); } if (tag.Length == 1) { obj = new Quote(obj); } Marshal(obj, false, cache); }
protected void Marshal(object o, bool asDictionaryKey, WriteCache cache) { bool supported = false; IWriteHandler h = GetHandler(o); if (h != null) { string t = h.Tag(o); if (t != null) { supported = true; if (t.Length == 1) { switch (t[0]) { case '_': EmitNull(asDictionaryKey, cache); break; case 's': EmitString(null, null, Escape((string)h.Representation(o)), asDictionaryKey, cache); break; case '?': EmitBoolean((bool)h.Representation(o), asDictionaryKey, cache); break; case 'i': EmitInteger(h.Representation(o), asDictionaryKey, cache); break; case 'd': EmitDouble(h.Representation(o), asDictionaryKey, cache); break; case 'b': EmitBinary(h.Representation(o), asDictionaryKey, cache); break; case '\'': EmitTagged(t, h.Representation(o), false, cache); break; default: EmitEncoded(t, h, o, asDictionaryKey, cache); break; } } else { if (t.Equals("array")) { EmitList(h.Representation(o), asDictionaryKey, cache); } else if (t.Equals("map")) { EmitDictionary(h.Representation(o), asDictionaryKey, cache); } else { EmitEncoded(t, h, o, asDictionaryKey, cache); } } FlushWriter(); } } if (!supported) { throw new NotSupportedException("Not supported: " + o.GetType()); } }
public string GetTag(object obj) { IWriteHandler handler = GetHandler(obj); if (handler == null) { return(null); } return(handler.Tag(obj)); }