public static GenerateForm BuilDuplicateJson(GenerateFormNoDupe noDupForm) { if (noDupForm == null || noDupForm.stringMap == null || noDupForm.checkboxMap == null) { return(null); } GenerateForm genForm = new GenerateForm(); foreach (KeyValuePair <string, Pair> entry in noDupForm.stringMap) { if (entry.Value.Count == 0) { genForm.stringMap[entry.Key] = entry.Value.Value; } else { for (int i = 0; i <= entry.Value.Count; i++) { genForm.stringMap[entry.Key + "_" + i] = entry.Value.Value; } } } genForm.checkboxMap = noDupForm.checkboxMap; return(genForm); }
public static GenerateFormNoDupe BuildNoDuplicateJson(GenerateForm genForm) { GenerateFormNoDupe noDupForm = new GenerateFormNoDupe(); foreach (KeyValuePair <string, string> entry in genForm.stringMap) { string key = entry.Key.Split('_')[0]; Pair valuePair; if (!noDupForm.stringMap.TryGetValue(key, out valuePair)) { noDupForm.stringMap[key] = new Pair(entry.Value, 0); } else { noDupForm.stringMap[key].Count++; } } noDupForm.checkboxMap = genForm.checkboxMap; return(noDupForm); }