public void Merge(Sheet source) { foreach (var sourceItem in source.items) { var item = items.FirstOrDefault(_ => _.key == sourceItem.key); if (item == null) { item = new Item { key = sourceItem.key }; items.Add(item); } foreach (var sourcePair in sourceItem.pairs) { var pair = item.pairs.FirstOrDefault(_ => _.language == sourcePair.language); if (pair == null) { pair = new Item.Pair { language = sourcePair.language }; item.pairs.Add(pair); } else { Debug.Log("conflict : " + sourceItem.key + ", " + sourcePair.language + ", [" + pair.text + " and " + sourcePair.text + "]"); } pair.text = sourcePair.text; } } }
public static Sheet Create(DoubleDictionary <string, string, string> languageKeyTextDictionary) { var result = new Sheet(); foreach (var(language, key, text) in languageKeyTextDictionary) { var item = result.items.FirstOrDefault(_ => _.key == key); if (item == null) { item = new Item { key = key }; result.items.Add(item); } var pair = new Item.Pair { language = language, text = text }; item.pairs.Add(pair); } return(result); }