Kaynağa Gözat

保证生成代码嵌套数据不冲突

lichunlei 3 ay önce
ebeveyn
işleme
20d8f48530
1 değiştirilmiş dosya ile 42 ekleme ve 0 silme
  1. 42 0
      Util/Maker.cs

+ 42 - 0
Util/Maker.cs

@@ -101,7 +101,28 @@ namespace Util
                                 }
                                 else
                                 {
+                                    Dictionary<string, string> replaceDict = new Dictionary<string, string>();
+                                    int index = 0;
+                                    MatchCollection subLoops = Regex.Matches(itemString, "<<ym-loop:.*?>>[\\s\\S]*?<</ym-loop:.*?>>");
+                                    foreach (Match subLoop in subLoops)
+                                    {
+                                        index += 1;
+                                        itemString = Regex.Replace(itemString, subLoop.Value, "${loop" + index + "}$");
+                                        replaceDict.Add("loop" + index, subLoop.Value);
+                                    }
+                                    index = 0;
+                                    MatchCollection subItems = Regex.Matches(itemString, "<<ym-item:.*?>>[\\s\\S]*?<</ym-item:.*?>>");
+                                    foreach (Match subItem in subItems)
+                                    {
+                                        index += 1;
+                                        itemString = Regex.Replace(itemString, subItem.Value, "${item" + index + "}$");
+                                        replaceDict.Add("item" + index, subItem.Value);
+                                    }
                                     itemString = itemString.Replace("<<" + itemKey + ">>", itemObj.ToString());
+                                    foreach (var replace in replaceDict)
+                                    {
+                                        itemString = itemString.Replace("${" + replace.Key + "}$", replace.Value);
+                                    }
                                 }
                             }
                             else
@@ -165,7 +186,28 @@ namespace Util
                             }
                             else
                             {
+                                Dictionary<string, string> replaceDict = new Dictionary<string, string>();
+                                int index = 0;
+                                MatchCollection subLoops = Regex.Matches(itemString, "<<ym-loop:.*?>>[\\s\\S]*?<</ym-loop:.*?>>");
+                                foreach (Match subLoop in subLoops)
+                                {
+                                    index += 1;
+                                    itemString = Regex.Replace(itemString, subLoop.Value, "${loop" + index + "}$");
+                                    replaceDict.Add("loop" + index, subLoop.Value);
+                                }
+                                index = 0;
+                                MatchCollection subItems = Regex.Matches(itemString, "<<ym-item:.*?>>[\\s\\S]*?<</ym-item:.*?>>");
+                                foreach (Match subItem in subItems)
+                                {
+                                    index += 1;
+                                    itemString = Regex.Replace(itemString, subItem.Value, "${item" + index + "}$");
+                                    replaceDict.Add("item" + index, subItem.Value);
+                                }
                                 itemString = itemString.Replace("<<" + itemKey + ">>", itemObj.ToString());
+                                foreach (var replace in replaceDict)
+                                {
+                                    itemString = itemString.Replace("${" + replace.Key + "}$", replace.Value);
+                                }
                             }
                         }
                         else