public virtual void Write(IWriteContext context, object obj) { if (obj == null) { context.WriteInt(0); return; } MarshallingContext marshallingContext = (MarshallingContext)context; ClassMetadata classMetadata = ClassMetadataFor(obj); if (classMetadata == null) { context.WriteInt(0); return; } MarshallingContextState state = marshallingContext.CurrentState(); marshallingContext.CreateChildBuffer(false); context.WriteInt(classMetadata.GetID()); WriteObject(context, classMetadata.TypeHandler(), obj); marshallingContext.RestoreState(state); }