Serialize() public static méthode

object动态类转换json包 add dukang by 2016-05-19
public static Serialize ( object obj, bool DateConvert = false ) : string
obj object 对象
DateConvert bool 时间戳是否转换成日期类型
Résultat string
        /// <summary>
        /// 执行日志
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <param name="isStarting"></param>
        protected virtual void ExecLogEvent(string sql, SqlParameter[] pars, bool isStarting = true)
        {
            if (this.IsEnableLogEvent)
            {
                Action <string, string> logAction;
                if (isStarting)
                {
                    this.CmdBeginTime = DateTime.Now;
                    logAction         = LogEventStarting;
                }
                else
                {
                    logAction = LogEventCompleted;
                }

                if (logAction != null)
                {
                    if (pars == null || pars.Length == 0)
                    {
                        logAction(sql, null);
                    }
                    else
                    {
                        logAction(sql, JsonConverter.Serialize(pars.Select(it => new { key = it.ParameterName, value = it.Value.ObjToString() })));
                    }
                }
            }
        }
Exemple #2
0
        private static string GetMessage(string message, object pars)
        {
            var parsStr = string.Empty;;

            if (pars != null)
            {
                parsStr = JsonConverter.Serialize(pars);
            }
            var reval = GetLineMessage("错误信息", message) + GetLineMessage("函数参数", parsStr);

            return(reval);
        }
Exemple #3
0
 private void ExecLogEvent(string sql, SqlParameter[] pars, bool isStarting = true)
 {
     if (IsEnableLogEvent)
     {
         Action <string, string> action = isStarting ? LogEventStarting : LogEventCompleted;
         if (action != null)
         {
             if (pars == null || pars.Length == 0)
             {
                 action(sql, null);
             }
             else
             {
                 action(sql, JsonConverter.Serialize(pars.Select(it => new { key = it.ParameterName, value = it.Value })));
             }
         }
     }
 }
Exemple #4
0
 private static string GetMessage(string message, string sql, object pars)
 {
     if (pars == null)
     {
         return(GetMessage(message, sql));
     }
     else
     {
         var reval = GetLineMessage("错误信息         ", message) + GetLineMessage("ORM生成的Sql", sql) + GetLineMessage("函数参数        ", JsonConverter.Serialize(pars));
         return(reval);
     }
 }