private IEnumerable<Event> GetEvents(int changedProjectCount, IVsProject[] changedProjects, int[] rgFirstIndices, int maxIndex) { foreach (var project in changedProjects.Take(changedProjectCount).Select((p, i) => new { Project = p, Index = i })) { if (project.Project != null) { var firstIndex = rgFirstIndices[project.Index]; var nextIndex = project.Index < rgFirstIndices.Length - 1 ? rgFirstIndices[project.Index + 1] : maxIndex; for (var itemIndex = firstIndex; itemIndex < nextIndex; itemIndex++) { yield return new Event { Project = project.Project, ItemIndex = itemIndex }; } } } }