|
@@ -76,8 +76,9 @@ namespace Util
|
|
|
//匹配要循环的模板内容
|
|
//匹配要循环的模板内容
|
|
|
string itemTemplate = matchValue.Replace(headValue, "").Replace("<</ym-loop:" + key + ">>", "");
|
|
string itemTemplate = matchValue.Replace(headValue, "").Replace("<</ym-loop:" + key + ">>", "");
|
|
|
//循环读取数组数据
|
|
//循环读取数组数据
|
|
|
- foreach (JsonData item in jsonObj)
|
|
|
|
|
|
|
+ for (int i = 0; i < jsonObj.Count; i++)
|
|
|
{
|
|
{
|
|
|
|
|
+ JsonData item = jsonObj[i];
|
|
|
string itemString = itemTemplate;
|
|
string itemString = itemTemplate;
|
|
|
// IDictionary<string, JsonData> itemData = item as IDictionary<string, JsonData>;
|
|
// IDictionary<string, JsonData> itemData = item as IDictionary<string, JsonData>;
|
|
|
//循环读取每个字段的数据
|
|
//循环读取每个字段的数据
|
|
@@ -178,11 +179,25 @@ namespace Util
|
|
|
string[] data = matchValue.Replace("<<ym:" + key + ".", "").Replace(">>", "").Split('.');
|
|
string[] data = matchValue.Replace("<<ym:" + key + ".", "").Replace(">>", "").Split('.');
|
|
|
if(data.Length == 1)
|
|
if(data.Length == 1)
|
|
|
{
|
|
{
|
|
|
- templateString = templateString.Replace(matchValue, jsonObj[key][data[0]].ToString());
|
|
|
|
|
|
|
+ if(jsonObj.ToJson().Contains("\"" + key + "\""))
|
|
|
|
|
+ {
|
|
|
|
|
+ templateString = templateString.Replace(matchValue, jsonObj[key][data[0]].ToString());
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ templateString = templateString.Replace(matchValue, jsonObj[data[0]].ToString());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
else if(data.Length == 2)
|
|
else if(data.Length == 2)
|
|
|
{
|
|
{
|
|
|
- templateString = templateString.Replace(matchValue, jsonObj[key][data[0]][data[1]].ToString());
|
|
|
|
|
|
|
+ if(jsonObj.ToJson().Contains("\"" + key + "\""))
|
|
|
|
|
+ {
|
|
|
|
|
+ templateString = templateString.Replace(matchValue, jsonObj[key][data[0]][data[1]].ToString());
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ templateString = templateString.Replace(matchValue, jsonObj[data[0]][data[1]].ToString());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return templateString;
|
|
return templateString;
|
|
@@ -210,9 +225,10 @@ namespace Util
|
|
|
}
|
|
}
|
|
|
string condition = headValue.Substring(8, headValue.Length - 10);
|
|
string condition = headValue.Substring(8, headValue.Length - 10);
|
|
|
condition = condition.Replace("isEmpty", "string.IsNullOrEmpty");
|
|
condition = condition.Replace("isEmpty", "string.IsNullOrEmpty");
|
|
|
|
|
+ condition = condition.Replace(".start(", ".StartsWith(");
|
|
|
condition = condition.Replace("True", "true");
|
|
condition = condition.Replace("True", "true");
|
|
|
condition = condition.Replace("False", "false");
|
|
condition = condition.Replace("False", "false");
|
|
|
- // Console.WriteLine(condition);
|
|
|
|
|
|
|
+ Console.WriteLine(condition);
|
|
|
bool result = await CSharpScript.EvaluateAsync<bool>(condition);
|
|
bool result = await CSharpScript.EvaluateAsync<bool>(condition);
|
|
|
content = content.Replace(matchValue, result ? resultValue : elseValue);
|
|
content = content.Replace(matchValue, result ? resultValue : elseValue);
|
|
|
}
|
|
}
|
|
@@ -224,29 +240,34 @@ namespace Util
|
|
|
#region 读取模版数据,替换对应的标签内容
|
|
#region 读取模版数据,替换对应的标签内容
|
|
|
public static string replaceKeyToValue(JsonData jsonObj, string templateString)
|
|
public static string replaceKeyToValue(JsonData jsonObj, string templateString)
|
|
|
{
|
|
{
|
|
|
|
|
+ if(templateString.Contains("<<ym.projectService.packageName>>"))
|
|
|
|
|
+ {
|
|
|
|
|
+ string packageName = "123123123";
|
|
|
|
|
+ }
|
|
|
MatchCollection mc = Regex.Matches(templateString, "<<.*?>>");
|
|
MatchCollection mc = Regex.Matches(templateString, "<<.*?>>");
|
|
|
foreach (Match m in mc)
|
|
foreach (Match m in mc)
|
|
|
{
|
|
{
|
|
|
string matchValue = m.Value;
|
|
string matchValue = m.Value;
|
|
|
string key = matchValue.Replace("<<", "").Replace(">>", "");
|
|
string key = matchValue.Replace("<<", "").Replace(">>", "");
|
|
|
- string[] keyArr = key.Split('.');
|
|
|
|
|
|
|
+ string[] keyArr = key.Replace("ym.", "").Split('.');
|
|
|
|
|
+ string jsonObjString = jsonObj.ToJson();
|
|
|
if (keyArr.Length == 1)
|
|
if (keyArr.Length == 1)
|
|
|
{
|
|
{
|
|
|
- if (jsonObj[key] != null)
|
|
|
|
|
|
|
+ if (jsonObjString.Contains("\"" + key + "\""))
|
|
|
{
|
|
{
|
|
|
templateString = templateString.Replace(matchValue, jsonObj[key].ToString());
|
|
templateString = templateString.Replace(matchValue, jsonObj[key].ToString());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else if (keyArr.Length == 2)
|
|
else if (keyArr.Length == 2)
|
|
|
{
|
|
{
|
|
|
- if (jsonObj[keyArr[0]] != null && jsonObj[keyArr[0]][keyArr[1]] != null)
|
|
|
|
|
|
|
+ if (jsonObjString.Contains("\"" + keyArr[0] + "\"") && jsonObjString.Contains("\"" + keyArr[1] + "\""))
|
|
|
{
|
|
{
|
|
|
templateString = templateString.Replace(matchValue, jsonObj[keyArr[0]][keyArr[1]].ToString());
|
|
templateString = templateString.Replace(matchValue, jsonObj[keyArr[0]][keyArr[1]].ToString());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else if (keyArr.Length == 3)
|
|
else if (keyArr.Length == 3)
|
|
|
{
|
|
{
|
|
|
- if (jsonObj[keyArr[0]] != null && jsonObj[keyArr[0]][keyArr[1]] != null && jsonObj[keyArr[0]][keyArr[1]][keyArr[2]] != null)
|
|
|
|
|
|
|
+ if (jsonObjString.Contains("\"" + keyArr[0] + "\"") && jsonObjString.Contains("\"" + keyArr[1] + "\"") && jsonObjString.Contains("\"" + keyArr[2] + "\""))
|
|
|
{
|
|
{
|
|
|
templateString = templateString.Replace(matchValue, jsonObj[keyArr[0]][keyArr[1]][keyArr[2]].ToString());
|
|
templateString = templateString.Replace(matchValue, jsonObj[keyArr[0]][keyArr[1]][keyArr[2]].ToString());
|
|
|
}
|
|
}
|