|
|
@@ -3,6 +3,7 @@ using System.Text.RegularExpressions;
|
|
|
using Common;
|
|
|
using LitJson;
|
|
|
using Microsoft.CodeAnalysis.CSharp.Scripting;
|
|
|
+using Microsoft.CodeAnalysis.Scripting;
|
|
|
|
|
|
namespace Util
|
|
|
{
|
|
|
@@ -10,7 +11,7 @@ namespace Util
|
|
|
{
|
|
|
|
|
|
#region 读取模版数据,替换对应的标签内容
|
|
|
- public static async Task<string> StartMake(JsonData jsonObj, string templateString)
|
|
|
+ public static string StartMake(JsonData jsonObj, string templateString)
|
|
|
{
|
|
|
foreach (string key in jsonObj.Keys)
|
|
|
{
|
|
|
@@ -20,12 +21,12 @@ namespace Util
|
|
|
if (obj.IsArray) //如果是数组
|
|
|
{
|
|
|
//匹配循环带loop循环标记的内容
|
|
|
- templateString = await makeArrayAsync(obj, templateString, key);
|
|
|
+ templateString = makeArrayAsync(obj, templateString, key);
|
|
|
}
|
|
|
else if (obj.IsObject) //如果是单个对象
|
|
|
{
|
|
|
//匹配循环带item单个对象标记的内容
|
|
|
- templateString = await makeObjectAsync(obj, templateString, key);
|
|
|
+ templateString = makeObjectAsync(obj, templateString, key);
|
|
|
}
|
|
|
else //否则当数值处理
|
|
|
{
|
|
|
@@ -37,11 +38,11 @@ namespace Util
|
|
|
templateString = templateString.Replace("<<ym:" + key + ">>", "");
|
|
|
}
|
|
|
}
|
|
|
- templateString = await PublicMakeAsync(templateString);
|
|
|
+ templateString = PublicMake(templateString);
|
|
|
return templateString;
|
|
|
}
|
|
|
|
|
|
- public static async Task<string> makeArrayAsync(JsonData jsonObj, string templateString, string key)
|
|
|
+ public static string makeArrayAsync(JsonData jsonObj, string templateString, string key)
|
|
|
{
|
|
|
MatchCollection mc = Regex.Matches(templateString, "<<ym-loop:" + key + ".*?>>[\\s\\S]*?<</ym-loop:" + key + ">>");
|
|
|
foreach (Match m in mc)
|
|
|
@@ -90,11 +91,11 @@ namespace Util
|
|
|
{
|
|
|
if (itemObj.IsArray)
|
|
|
{
|
|
|
- itemString = await makeArrayAsync(itemObj, itemString, itemKey);
|
|
|
+ itemString = makeArrayAsync(itemObj, itemString, itemKey);
|
|
|
}
|
|
|
else if (itemObj.IsObject)
|
|
|
{
|
|
|
- itemString = await makeObjectAsync(itemObj, itemString, itemKey);
|
|
|
+ itemString = makeObjectAsync(itemObj, itemString, itemKey);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -104,11 +105,13 @@ namespace Util
|
|
|
else
|
|
|
{
|
|
|
itemString = itemString.Replace("<<" + itemKey + ">>", "");
|
|
|
+ itemString = Regex.Replace(itemString, "<<ym-loop:" + key + ".*?>>[\\s\\S]*?<</ym-loop:" + key + ">>", "");
|
|
|
+ itemString = Regex.Replace(itemString, "<<ym-item:" + key + ".*?>>[\\s\\S]*?<</ym-item:" + key + ">>", "");
|
|
|
}
|
|
|
}
|
|
|
listString += itemString;
|
|
|
}
|
|
|
- listString = await PublicMakeAsync(listString);
|
|
|
+ listString = PublicMake(listString);
|
|
|
//过滤两头的符号
|
|
|
if (removeString.Length > 0)
|
|
|
{
|
|
|
@@ -130,7 +133,7 @@ namespace Util
|
|
|
return templateString;
|
|
|
}
|
|
|
|
|
|
- public static async Task<string> makeObjectAsync(JsonData jsonObj, string templateString, string key)
|
|
|
+ public static string makeObjectAsync(JsonData jsonObj, string templateString, string key)
|
|
|
{
|
|
|
MatchCollection mc = Regex.Matches(templateString, "<<ym-item:" + key + ".*?>>[\\s\\S]*?<</ym-item:" + key + ">>");
|
|
|
foreach (Match m in mc)
|
|
|
@@ -152,11 +155,11 @@ namespace Util
|
|
|
{
|
|
|
if (itemObj.IsArray)
|
|
|
{
|
|
|
- itemString = await makeArrayAsync(itemObj, itemString, itemKey);
|
|
|
+ itemString = makeArrayAsync(itemObj, itemString, itemKey);
|
|
|
}
|
|
|
else if (itemObj.IsObject)
|
|
|
{
|
|
|
- itemString = await makeObjectAsync(itemObj, itemString, itemKey);
|
|
|
+ itemString = makeObjectAsync(itemObj, itemString, itemKey);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -166,6 +169,8 @@ namespace Util
|
|
|
else
|
|
|
{
|
|
|
itemString = itemString.Replace("<<" + itemKey + ">>", "");
|
|
|
+ itemString = Regex.Replace(itemString, "<<ym-loop:" + key + ".*?>>[\\s\\S]*?<</ym-loop:" + key + ">>", "");
|
|
|
+ itemString = Regex.Replace(itemString, "<<ym-item:" + key + ".*?>>[\\s\\S]*?<</ym-item:" + key + ">>", "");
|
|
|
}
|
|
|
}
|
|
|
listString += itemString;
|
|
|
@@ -205,7 +210,7 @@ namespace Util
|
|
|
#endregion
|
|
|
|
|
|
#region 公共标签处理
|
|
|
- public static async Task<string> PublicMakeAsync(string content)
|
|
|
+ public static string PublicMake(string content)
|
|
|
{
|
|
|
MatchCollection mc = Regex.Matches(content, "<<ym-if:.*?>>[\\s\\S]*?<</ym-if>>");
|
|
|
foreach (Match m in mc)
|
|
|
@@ -224,12 +229,13 @@ namespace Util
|
|
|
elseValue = valueData[1];
|
|
|
}
|
|
|
string condition = headValue.Substring(8, headValue.Length - 10);
|
|
|
- condition = condition.Replace("isEmpty", "string.IsNullOrEmpty");
|
|
|
- condition = condition.Replace(".start(", ".StartsWith(");
|
|
|
+ condition = condition.Replace("isEmpty", "IsNullOrEmpty");
|
|
|
+ condition = condition.Replace("start(", "StartsWith(");
|
|
|
condition = condition.Replace("True", "true");
|
|
|
condition = condition.Replace("False", "false");
|
|
|
+ condition = condition.Replace("\"", "'");
|
|
|
// Console.WriteLine(condition);
|
|
|
- bool result = await CSharpScript.EvaluateAsync<bool>(condition);
|
|
|
+ bool result = Utils.EvaluateBoolean(condition);
|
|
|
content = content.Replace(matchValue, result ? resultValue : elseValue);
|
|
|
}
|
|
|
}
|