Skip to content

Commit

Permalink
386:AutoCache(JsonHelper增加Escape属性、MDataTable增加ToJson重载)不处理\n的转义替换(20…
Browse files Browse the repository at this point in the history
…16-10-09)
  • Loading branch information
cyq1162 committed Oct 9, 2016
1 parent 16c99a4 commit a55188c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cache/AutoCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ internal static void SetCache(AopEnum action, AopInfo aopInfo)//End
JsonHelper js = new JsonHelper(false, false);
foreach (MDataTable table in aopInfo.TableList)
{
js.Add(Guid.NewGuid().ToString(), table.ToJson(true, true, RowOp.IgnoreNull));
js.Add(Guid.NewGuid().ToString(), table.ToJson(true, true, RowOp.IgnoreNull,false, EscapeOp.No));
}
js.AddBr();
_MemCache.Set(key, js.ToString(), cacheTime);
Expand All @@ -151,7 +151,7 @@ internal static void SetCache(AopEnum action, AopInfo aopInfo)//End
case AopEnum.ExeMDataTable:
if (IsCanCache(aopInfo.Table))
{
_MemCache.Set(key, aopInfo.Table.ToJson(true, true, RowOp.IgnoreNull), cacheTime);
_MemCache.Set(key, aopInfo.Table.ToJson(true, true, RowOp.IgnoreNull, false, EscapeOp.No), cacheTime);
}
break;
case AopEnum.ExeScalar:
Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[assembly: AssemblyTitle("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyDescription("论坛:http://www.cyqdata.com/cyqdata")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("秋式软件 (2016-10-08)")]
[assembly: AssemblyCompany("秋式软件 (2016-10-09)")]
[assembly: AssemblyProduct("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyCopyright("版权所有 (C) 秋式软件 2010-2020")]
[assembly: AssemblyTrademark("CYQ.Data")]
Expand All @@ -31,5 +31,5 @@
//
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("5.6.6.1")]
[assembly: AssemblyFileVersion("5.6.6.1")]
[assembly: AssemblyVersion("5.6.6.2")]
[assembly: AssemblyFileVersion("5.6.6.2")]
16 changes: 11 additions & 5 deletions Table/MDataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,26 +424,32 @@ public string ToJson()
{
return ToJson(true, false);
}
/// <param name="addHead">输出头部信息[带count、Success、ErrorMsg]</param>
/// <param name="addSchema">首行输出表架构信息,反接收时可还原架构</param>
public string ToJson(bool addHead, bool addSchema)
{
return ToJson(addHead, addSchema, RowOp.IgnoreNull);
}
/// <param name="isConvertNameToLower">是否将名称转为小写</param>
public string ToJson(bool addHead, bool addSchema, bool isConvertNameToLower)
{
return ToJson(addHead, addSchema, RowOp.IgnoreNull, isConvertNameToLower);
}
/// <param name="rowOp">过滤选项</param>
public string ToJson(bool addHead, bool addSchema, RowOp rowOp)
{
return ToJson(addHead, addSchema, rowOp, false);
}
/// <param name="addHead">输出头部信息[带count、Success、ErrorMsg]</param>
/// <param name="addSchema">首行输出表架构信息,反接收时可还原架构</param>
/// <param name="rowOp">过滤选项</param>
/// <param name="isConvertNameToLower">是否将名称转为小写</param>
/// <returns></returns>

public string ToJson(bool addHead, bool addSchema, RowOp rowOp, bool isConvertNameToLower)
{
return ToJson(addHead, addSchema, rowOp, false, EscapeOp.Default);
}
/// <param name="op">符号转义选项</param>
public string ToJson(bool addHead, bool addSchema, RowOp rowOp, bool isConvertNameToLower, EscapeOp op)
{
JsonHelper helper = new JsonHelper(addHead, addSchema);
helper.Escape = op;
helper.IsConvertNameToLower = isConvertNameToLower;
helper.RowOp = rowOp;
helper.Fill(this);
Expand Down
23 changes: 18 additions & 5 deletions Tool/JsonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,24 @@

namespace CYQ.Data.Tool
{
/// <summary>
/// JsonHelper 的符号转义选项
/// </summary>
public enum EscapeOp
{
/// <summary>
/// Web 默认转义,Win不转义
/// </summary>
Default,
No,
Yes
}
/// <summary>
/// json 帮助类
/// </summary>
public partial class JsonHelper
{

#region 实例属性

public JsonHelper()
Expand All @@ -35,10 +48,10 @@ public JsonHelper(bool addHead, bool addSchema)
_AddSchema = addSchema;
}
#region 属性
///// <summary>
///// 是否转义转义符号(默认true)
///// </summary>
//public bool IsEscapeChar = true;
/// <summary>
/// 转义符号
/// </summary>
public EscapeOp Escape = EscapeOp.Default;
/// <summary>
/// 是否将名称转为小写
/// </summary>
Expand Down Expand Up @@ -294,7 +307,7 @@ public override string ToString()
sb.Append(footText + "}");
}
string json = sb.ToString();
if (System.Web.HttpContext.Current != null) // Web应用
if ((Escape == EscapeOp.Default && System.Web.HttpContext.Current != null) || Escape == EscapeOp.Yes) // Web应用
{
json = json.Replace("\n", "<br/>").Replace("\t", " ").Replace("\r", " ");
}
Expand Down
3 changes: 2 additions & 1 deletion 更新记录.txt
Original file line number Diff line number Diff line change
Expand Up @@ -598,4 +598,5 @@
382��MAction �ڲ�����IsIgnoreDeleteField �ڲ����ԣ�2016-09-30)
383��XHtmlBase ������Xml�ļ��أ�2016-10-08)
384��SqlValue �����������ƣ�GUID��ISNULL����������2016-10-08)
385��MDataTable ����Select����Ϊ<=�������ж����⣨2016-10-08)
385��MDataTable ����Select����Ϊ<=�������ж����⣨2016-10-08)
386��AutoCache��JsonHelper����Escape���ԡ�MDataTable����ToJson���أ�������\n��ת���滻��2016-10-09)

0 comments on commit a55188c

Please sign in to comment.