예제 #1
0
        /// <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);
        }
예제 #2
0
파일: Extensions.cs 프로젝트: yk2012985/wpf
        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);
        }
예제 #3
0
            private List <SpellingError> CheckImpl(string text)
            {
                IEnumSpellingError errors = _speller.Value.Check(text);

                return((errors != null) ? errors.ToList(this, text, false, true) : null);
            }
예제 #4
0
            public List <SpellingError> ComprehensiveCheckImpl(string text)
            {
                IEnumSpellingError errors = _speller.Value.ComprehensiveCheck(text);

                return((errors != null) ? errors.ToList(this, text, false, true) : null);
            }
예제 #5
0
            // 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);
            }