public void CombineSources() { List <Score> scoreList = new List <Score>(); for (int i = 0; i < m_sources.Count; ++i) { for (int k = i + 1; k < m_sources.Count; ++k) { scoreList.Add(Source.GetScore(m_sources[i], m_sources[k])); } } scoreList.Sort((lhs, rhs) => rhs.MatchCount - lhs.MatchCount); for (int i = 0; i < scoreList.Count; ++i) { Score score = scoreList[i]; if (CanCombine(score.Lhs, score.Rhs) == false) { continue; } Source combinedSource = Source.Combine(score.Lhs, score.Rhs); //Do not dispose lhs, rhs sources //these just moved so must not be released. m_sources.Remove(score.Lhs); m_sources.Remove(score.Rhs); m_sources.Add(combinedSource); //Remove merged Score and make Score by combinedScore. scoreList.RemoveAll(s => s.Lhs == score.Lhs || s.Lhs == score.Rhs || s.Rhs == score.Lhs || s.Rhs == score.Rhs); //last is combinedSource. for (int k = 0; k < m_sources.Count - 1; ++k) { scoreList.Add(Source.GetScore(m_sources[k], combinedSource)); } scoreList.Sort((lhs, rhs) => rhs.MatchCount - lhs.MatchCount); i = -1; //for back to the first loop.. } }