/// <summary> /// 对象转换XML字符串 /// </summary> /// <typeparam name="valueType">目标数据类型</typeparam> /// <param name="value">数据对象</param> private void serialize <valueType>(valueType value) { Warning = SerializeWarning.None; if (checkLoopDepth != Config.CheckLoopDepth) { if (Config.CheckLoopDepth <= 0) { checkLoopDepth = 0; if (forefather == null) { forefather = new object[sizeof(int)]; } } else { checkLoopDepth = Config.CheckLoopDepth; } } CharStream.Write(Config.Header); fixed(char *nameFixed = Config.BootNodeName) { nameStart(nameFixed, Config.BootNodeName.Length); TypeSerializer <valueType> .Serialize(this, value); nameEnd(nameFixed, Config.BootNodeName.Length); } }
/// <summary> /// 对象转换 JSON 字符串(线程静态实例模式) /// </summary> /// <typeparam name="T">目标数据类型</typeparam> /// <param name="value">数据对象</param> /// <param name="warning">警告提示状态</param> /// <param name="config">配置参数</param> /// <returns>JSON 字符串</returns> public static string ThreadStaticSerialize <T>(ref T value, out SerializeWarning warning, SerializeConfig config = null) { JsonSerializer jsonSerializer = ThreadStaticSerializer.Get().Serializer; try { string json = jsonSerializer.serializeThreadStatic(ref value, config); warning = jsonSerializer.Warning; return(json); } finally { jsonSerializer.freeThreadStatic(); } }
/// <summary> /// 对象转换JSON字符串 /// </summary> /// <typeparam name="valueType">目标数据类型</typeparam> /// <param name="value">数据对象</param> private void serialize <valueType>(ref valueType value) { if (Config.GetLoopObject == null || Config.SetLoopObject == null) { if (Config.GetLoopObject != null) { Warning = SerializeWarning.LessSetLoop; } else if (Config.SetLoopObject != null) { Warning = SerializeWarning.LessGetLoop; } else { Warning = SerializeWarning.None; } if (checkLoopDepth != Config.CheckLoopDepth || isLoopObject) { if (Config.CheckLoopDepth <= 0) { checkLoopDepth = 0; if (forefather == null) { forefather = new object[sizeof(int)]; } } else { checkLoopDepth = Config.CheckLoopDepth; } } isLoopObject = false; } else { if (!isLoopObject) { isLoopObject = true; if (objectIndexs == null) { objectIndexs = DictionaryCreator <ObjectReference> .Create <string>(); } } Warning = SerializeWarning.None; checkLoopDepth = Config.CheckLoopDepth <= 0 ? SerializeConfig.DefaultCheckLoopDepth : Config.CheckLoopDepth; } TypeSerializer <valueType> .Serialize(this, value); }
public static string ThreadStaticSerialize <T>(T value, out SerializeWarning warning, SerializeConfig config = null) { return(ThreadStaticSerialize(ref value, out warning, config)); }