/// <summary> /// 对象转换JSON字符串 /// </summary> /// <typeparam name="valueType">目标数据类型</typeparam> /// <param name="value">数据对象</param> /// <param name="config">配置参数</param> /// <returns>Json字符串</returns> private string serialize <valueType>(ref valueType value, SerializeConfig config) { Config = config ?? DefaultConfig; AutoCSer.Memory.Pointer buffer = UnmanagedPool.Default.GetPointer(); try { CharStream.Reset(ref buffer); using (CharStream) { serialize(ref value); return(CharStream.ToString()); } } finally { UnmanagedPool.Default.PushOnly(ref buffer); } }
/// <summary> /// 对象转换JSON字符串 /// </summary> /// <typeparam name="valueType">目标数据类型</typeparam> /// <param name="value">数据对象</param> /// <param name="onSerializeStream">序列化以后的数据流处理事件</param> /// <param name="config">配置参数</param> private void serialize <valueType>(ref valueType value, Action <CharStream> onSerializeStream, SerializeConfig config) { Config = config ?? DefaultConfig; AutoCSer.Memory.Pointer buffer = UnmanagedPool.Default.GetPointer(); try { CharStream.Reset(ref buffer); using (CharStream) { serialize(ref value); onSerializeStream(CharStream); } } finally { UnmanagedPool.Default.PushOnly(ref buffer); } }