/// <summary> /// Map several phoneset to a new phoneset using the mapPhone delegate. /// </summary> /// <param name="phoneQuestions">Phone questions to be mapped.</param> /// <param name="mapPhone">MapPhone delegate map original phone to new phone.</param> /// <returns>Mapped phonesets.</returns> public static PhoneQuestion[] Convert(IEnumerable<PhoneQuestion> phoneQuestions, MapPhone mapPhone) { List<PhoneQuestion> questions = new List<PhoneQuestion>(); foreach (PhoneQuestion set in phoneQuestions) { questions.Add(Convert(set, mapPhone)); } return RemoveDuplicate(questions); }
/// <summary> /// Convert phoneset to the mapped phoneset, using delegate mapPhone, if the parameter /// Delimiters is not null, mapped phones string will be splitted to several phones /// And added to the new phone set. /// </summary> /// <param name="phoneQuestion">Phone set to be converted.</param> /// <param name="mapPhone">Map old phone to new phone delegate.</param> /// <returns>Mapped phoneset.</returns> public static PhoneQuestion Convert(PhoneQuestion phoneQuestion, MapPhone mapPhone) { PhoneQuestion question = new PhoneQuestion(phoneQuestion.Name); foreach (string phone in phoneQuestion.Phones) { string[] mappedPhones = mapPhone(phone); if (mappedPhones == null || mappedPhones.Length <= 0 || string.IsNullOrEmpty(mappedPhones[0])) { string message = Helper.NeutralFormat("Can't find phone [{0}]'s " + "mapped phone in phoneset [{1}]", phone, phoneQuestion.Name); continue; } foreach (string mappedPhone in mappedPhones) { question.Phones.Add(mappedPhone); } } return question; }