public static void Serialize <T>(Stream stream, T obj) { Debug.Assert(_state != null, "State can't be null"); if (obj == null) { _state.InstanceCannotBeNull(); } var description = _state.GetDescription(RuntimeHelpers.GetHashCode(typeof(T))); if (description == null) { _state.TypeNotSupported(obj.GetType()); } var writer = WriterPool.GetFormatter(stream, Encoding); try { writer.Write(description.TypeId); ((SpecializedTypeDescription <T>)description).SerializeHanlder(obj, writer); } finally { WriterPool.ReleaseFormatter(writer); } }
public static void Serialize(Stream stream, object obj) { Debug.Assert(_state != null, "State can't be null"); if (obj == null) { _state.InstanceCannotBeNull(); } var description = _state.GetDescription(obj.GetType()); if (description == null) { _state.TypeNotSupported(obj.GetType()); } var writer = WriterPool.GetFormatter(stream, Encoding); try { writer.Write(description.TypeId); description.Serialize(writer, obj); } finally { WriterPool.ReleaseFormatter(writer); } }