/// <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); }
private List <SpellingError> CheckImpl(string text) { IEnumSpellingError errors = _speller.Value.Check(text); return((errors != null) ? errors.ToList(this, text, false, true) : null); }
public List <SpellingError> ComprehensiveCheckImpl(string text) { IEnumSpellingError errors = _speller.Value.ComprehensiveCheck(text); return((errors != null) ? errors.ToList(this, text, false, true) : null); }
// This returns true if the given text has any spelling errors. // It is a shortcut for // ComprehensiveCheck(text)?.Count != 0 // that avoids the (expensive) creation of the managed list of errors and // their suggested corrections. public bool HasErrorsImpl(string text) { IEnumSpellingError errors = _speller.Value.ComprehensiveCheck(text); return((errors != null) ? errors.HasErrors(false, true) : false); }