internal static List <SpellChecker.SpellingError> ToList(this RCW.IEnumSpellingError spellingErrors, SpellChecker spellChecker, string text, bool shouldSuppressCOMExceptions = true, bool shouldReleaseCOMObject = true) { if (spellingErrors == null) { throw new ArgumentNullException("spellingErrors"); } List <SpellChecker.SpellingError> list = new List <SpellChecker.SpellingError>(); try { for (;;) { RCW.ISpellingError spellingError = spellingErrors.Next(); if (spellingError == null) { break; } SpellChecker.SpellingError item = new SpellChecker.SpellingError(spellingError, spellChecker, text, shouldSuppressCOMExceptions, true); list.Add(item); } } catch (COMException obj) when(shouldSuppressCOMExceptions) { } finally { if (shouldReleaseCOMObject) { Marshal.ReleaseComObject(spellingErrors); } } return(list); }
internal SpellingError(RCW.ISpellingError error, SpellChecker spellChecker, string text, bool shouldSuppressCOMExceptions = true, bool shouldReleaseCOMObject = true) { if (error == null) { throw new ArgumentNullException("error"); } this.StartIndex = error.StartIndex; this.Length = error.Length; this.CorrectiveAction = error.CorrectiveAction; this.Replacement = error.Replacement; this.PopulateSuggestions(error, spellChecker, text, shouldSuppressCOMExceptions, shouldReleaseCOMObject); }
private void PopulateSuggestions(RCW.ISpellingError error, SpellChecker spellChecker, string text, bool shouldSuppressCOMExceptions, bool shouldReleaseCOMObject) { try { this._suggestions = new List <string>(); if (this.CorrectiveAction == SpellChecker.CorrectiveAction.GetSuggestions) { List <string> collection = spellChecker.Suggest(text, shouldSuppressCOMExceptions); this._suggestions.AddRange(collection); } else if (this.CorrectiveAction == SpellChecker.CorrectiveAction.Replace) { this._suggestions.Add(this.Replacement); } } finally { if (shouldReleaseCOMObject) { Marshal.ReleaseComObject(error); } } }