public void WriteData(ObjectEncoding objectEncoding, object data) { if (data == null) { WriteNull(); return; } Type type = data.GetType(); if (amf0ObjectReferences.ContainsKey(data)) { WriteReference(data); return; } IAMFWriter amfWriter = null; if (AmfWriterTable[0].ContainsKey(type)) { amfWriter = AmfWriterTable[0][type] as IAMFWriter; } if (amfWriter == null) { if (type.BaseType != null) { if (AmfWriterTable[0].ContainsKey(type.BaseType)) { amfWriter = AmfWriterTable[0][type.BaseType] as IAMFWriter; } } } if (amfWriter == null) { amfWriter = new AMF0ObjectWriter(); } if (objectEncoding == ObjectEncoding.AMF0) { amfWriter.WriteData(this, data); } else { if (amfWriter.IsPrimitive) { amfWriter.WriteData(this, data); } else { WriteByte(AMF0TypeCode.AMF3Tag); WriteAMF3Data(data); } } }
public void WriteData(ObjectEncoding objectEncoding, object data) { if (data == null) { this.WriteNull(); } else { Type type = data.GetType(); if ((FluorineConfiguration.Instance.AcceptNullValueTypes && (FluorineConfiguration.Instance.NullableValues != null)) && (FluorineConfiguration.Instance.NullableValues.ContainsKey(type) && data.Equals(FluorineConfiguration.Instance.NullableValues[type]))) { this.WriteNull(); } else if (this._amf0ObjectReferences.ContainsKey(data)) { this.WriteReference(data); } else { IAMFWriter writer = null; if (AmfWriterTable[0].ContainsKey(type)) { writer = AmfWriterTable[0][type]; } if ((writer == null) && AmfWriterTable[0].ContainsKey(type.BaseType)) { writer = AmfWriterTable[0][type.BaseType]; } if (writer == null) { lock (AmfWriterTable) { if (!AmfWriterTable[0].ContainsKey(type)) { writer = new AMF0ObjectWriter(); AmfWriterTable[0].Add(type, writer); } else { writer = AmfWriterTable[0][type]; } } } if (writer == null) { throw new FluorineException(__Res.GetString("TypeSerializer_NotFound", new object[] { type.FullName })); } if (objectEncoding == ObjectEncoding.AMF0) { writer.WriteData(this, data); } else if (writer.IsPrimitive) { writer.WriteData(this, data); } else { this.WriteByte(0x11); this.WriteAMF3Data(data); } } } }