/// <summary> /// Determines whether an RCW.IEnumSpellingError instance has any errors, /// without asking for expensive details. /// </summary> internal static bool HasErrors( this IEnumSpellingError spellingErrors, bool shouldSuppressCOMExceptions = true, bool shouldReleaseCOMObject = true) { if (spellingErrors == null) { throw new ArgumentNullException(nameof(spellingErrors)); } bool result = false; try { while (!result) { ISpellingError iSpellingError = spellingErrors.Next(); if (iSpellingError == null) { // no more ISpellingError objects left in the enum break; } if ((CorrectiveAction)iSpellingError.CorrectiveAction != CorrectiveAction.None) { result = true; } Marshal.ReleaseComObject(iSpellingError); } } catch (COMException) when(shouldSuppressCOMExceptions) { // do nothing here // the exception filter does it all. } finally { if (shouldReleaseCOMObject) { Marshal.ReleaseComObject(spellingErrors); } } return(result); }
internal static List <SpellingError> ToList( this IEnumSpellingError spellingErrors, SpellChecker spellChecker, string text, bool shouldSuppressCOMExceptions = true, bool shouldReleaseCOMObject = true) { if (spellingErrors == null) { throw new ArgumentNullException(nameof(spellingErrors)); } var result = new List <SpellingError>(); try { while (true) { ISpellingError iSpellingError = spellingErrors.Next(); if (iSpellingError == null) { // no more ISpellingError objects left in the enum break; } var error = new SpellingError(iSpellingError, spellChecker, text, shouldSuppressCOMExceptions, true); result.Add(error); } } catch (COMException) when(shouldSuppressCOMExceptions) { // do nothing here // the exception filter does it all. } finally { if (shouldReleaseCOMObject) { Marshal.ReleaseComObject(spellingErrors); } } return(result); }