/// ------------------------------------------------------------------------------------ /// <summary> /// Returns an enumerator that iterates through the collection of questions. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to /// iterate through the collection. /// </returns> /// ------------------------------------------------------------------------------------ public static void GenerateAlternateForms(QuestionSections sections, Dictionary <string, string[]> alternatives) { string[] altForms; foreach (Section section in sections.Items) { foreach (Category category in section.Categories) { if (category.Questions == null) { continue; } foreach (Question q in category.Questions) { if (alternatives != null && alternatives.TryGetValue(q.Text, out altForms)) { q.AlternateForms = altForms; } else { QuestionProviderAlternateFormBuilder bldr = new QuestionProviderAlternateFormBuilder(q.Text); if (bldr.Alternatives.Count > 1) { q.AlternateForms = new string[bldr.Alternatives.Count]; for (int index = 0; index < bldr.Alternatives.Count; index++) { q.AlternateForms[index] = bldr.Alternatives[index]; } } } } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Returns an enumerator that iterates through the collection of questions. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to /// iterate through the collection. /// </returns> /// ------------------------------------------------------------------------------------ public static void GenerateAlternateForms(QuestionSections sections, Dictionary <string, string[]> alternatives) { foreach (Section section in sections.Items) { foreach (Category category in section.Categories) { if (category.Questions == null) { continue; } foreach (Question q in category.Questions) { if (alternatives != null && alternatives.TryGetValue(q.Text, out var altForms)) { q.Alternatives = altForms.Select(f => new AlternativeForm { Text = f }).ToArray(); } else { var bldr = new QuestionProviderAlternateFormBuilder(q.Text); if (bldr.Alternatives.Count > 1) { q.Alternatives = bldr.Alternatives.Select(f => new AlternativeForm { Text = f }).ToArray(); } } } } } }