diff --git a/.gitignore b/.gitignore index ae61d95..bb22de0 100644 --- a/.gitignore +++ b/.gitignore @@ -56,4 +56,5 @@ build/ [Bb]in/ [Oo]bj/ -builds/local \ No newline at end of file +builds/local +.vs/ diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config deleted file mode 100644 index 67f8ea0..0000000 --- a/.nuget/NuGet.Config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.nuget/nuget.exe b/.nuget/nuget.exe deleted file mode 100644 index 8dd7e45..0000000 Binary files a/.nuget/nuget.exe and /dev/null differ diff --git a/NuSpec/SpellCheck.nuspec b/NuSpec/SpellCheck.nuspec deleted file mode 100644 index fed6b06..0000000 --- a/NuSpec/SpellCheck.nuspec +++ /dev/null @@ -1,25 +0,0 @@ - - - - PlatformSpellCheck - 1.0.0 - Spell Check - bbowyersmyth - bbowyersmyth - https://raw.githubusercontent.com/bbowyersmyth/SpellCheck/master/License.md - http://github.com/bbowyersmyth/spellcheck - false - Managed wrapper for the Microsoft Spell Checking API - Managed wrapper for the Microsoft Spell Checking API - - UserDictionariesRegistrar, LanguageTag, Add, and AutoCorrect - - spell checker check spell-check spell-checker spellchecker spellcheck suggestion - - - - - - - - diff --git a/build.cmd b/build.cmd index 5f77124..8b4e85b 100644 --- a/build.cmd +++ b/build.cmd @@ -1,5 +1,6 @@ -msbuild src\SpellCheck.sln /t:clean /p:Configuration=Release /p:Platform="Any CPU" -msbuild src\SpellCheck.sln /p:Configuration=Release /p:Platform="Any CPU" /p:VisualStudioVersion=12.0 -md builds -md builds\local -.\.NuGet\nuget.exe pack NuSpec\SpellCheck.nuspec -OutputDirectory builds\local +@echo off +msbuild src\SpellCheck.sln /t:clean /p:Configuration=Release /p:Platform="Any CPU" /m +msbuild src\SpellCheck.sln /p:Configuration=Release /p:Platform="Any CPU" /p:VisualStudioVersion=14.0 /m +if not exist builds md builds +if not exist builds\local md builds\local +copy src\SpellCheck\bin\Release\*.nupkg builds\local diff --git a/src/SpellCheck.Tests/Properties/AssemblyInfo.cs b/src/SpellCheck.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 65bd8dd..0000000 --- a/src/SpellCheck.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SpellCheck.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SpellCheck.Tests")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("11679e18-4ce9-4b9d-90ec-1832d8d245c2")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/SpellCheck.Tests/SpellCheck.Tests.csproj b/src/SpellCheck.Tests/SpellCheck.Tests.csproj index bc728d2..48e7c96 100644 --- a/src/SpellCheck.Tests/SpellCheck.Tests.csproj +++ b/src/SpellCheck.Tests/SpellCheck.Tests.csproj @@ -1,92 +1,26 @@ - - + + - Debug - AnyCPU - {68057238-23BD-470C-980F-C5DADDF62E4E} - Library - Properties + netcoreapp3.0 + + false + PlatformSpellCheck.Tests + PlatformSpellCheck.Tests - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest + + Bruce Bowyer-Smyth - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - 3.5 - - - - - - - - - - - - - - + - - + + + + + - - {6d5e0752-9f30-413b-9d9c-6b65850606c7} - SpellCheck - + - - - - - False - - - False - - - False - - - False - - - - - - - - \ No newline at end of file + + diff --git a/src/SpellCheck.Tests/SpellCheckerTests.cs b/src/SpellCheck.Tests/SpellCheckerTests.cs index 80698ed..68ced95 100644 --- a/src/SpellCheck.Tests/SpellCheckerTests.cs +++ b/src/SpellCheck.Tests/SpellCheckerTests.cs @@ -1,46 +1,27 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Linq; +// +// Copyright © Bruce Bowyer-Smyth. All rights reserved. +// namespace PlatformSpellCheck.Tests { + using System; + using System.Linq; + + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Defines test class SpellCheckerTests. + /// [TestClass] public class SpellCheckerTests { - [TestMethod] - public void IsPlatformSupportedTest() - { - Assert.IsTrue(SpellChecker.IsPlatformSupported()); - } - - [TestMethod] - public void IsLanguageSupportedTest() - { - Assert.IsTrue(SpellChecker.IsLanguageSupported("en-us")); - Assert.IsFalse(SpellChecker.IsLanguageSupported("zz-zz")); - } - - [TestMethod] - public void SupportedLanguagesTest() - { - Assert.IsTrue(SpellChecker.SupportedLanguages.Any()); - } - - [TestMethod] - public void SuggestionsTest() - { - var spell = new SpellChecker(); - - var examples = spell.Suggestions("manle"); - - Assert.IsTrue(examples.Any()); - } - + /// + /// Defines the test method CheckTest. + /// [TestMethod] public void CheckTest() { - var spell = new SpellChecker("en-us"); - + using var spell = new SpellChecker("en-us"); var examples = spell.Check("foxx or recieve").ToList(); Assert.AreEqual(examples.Count(), 2); @@ -60,57 +41,111 @@ public void CheckTest() Assert.AreEqual(secondError.RecommendedReplacement, "receive"); } + /// + /// Defines the test method DoubleDisposeTest. + /// [TestMethod] - public void MultiSessionTest() + public void DoubleDisposeTest() { - var spell1 = new SpellChecker("en-us"); - var spell2 = new SpellChecker("fr-fr"); - - var examples1 = spell1.Suggestions("doog").ToList(); - spell1.Dispose(); - var examples2 = spell2.Suggestions("doog").ToList(); - - Assert.AreEqual(examples1.Count(), 4); - Assert.AreEqual(examples2.Count(), 2); - } + var spell = new SpellChecker("en-AU"); - [TestMethod, ExpectedException(typeof(ArgumentException))] - public void UnsupportedLangTest() - { - var spell = new SpellChecker("zz-zz"); + spell.Dispose(); + spell.Dispose(); // No error } + /// + /// Defines the test method IgnoreTest. + /// [TestMethod] public void IgnoreTest() { - var spell = new SpellChecker(); - - var examples = spell.Check("codez"); + // ReSharper disable once StringLiteralTypo + // ReSharper disable IdentifierTypo + const string codez = "codez"; + using var spell = new SpellChecker(); + var examples = spell.Check(codez); Assert.IsTrue(examples.Any()); - spell.Ignore("codez"); + spell.Ignore(codez); - examples = spell.Check("codez"); + examples = spell.Check(codez); Assert.AreEqual(examples.Count(), 0); + + // ReSharper restore IdentifierTypo } + /// + /// Defines the test method IsLanguageSupportedTest. + /// [TestMethod] - public void LanguageIdTest() + public void IsLanguageSupportedTest() { - var spell = new SpellChecker("en-AU"); + Assert.IsTrue(SpellChecker.IsLanguageSupported("en-us")); + Assert.IsFalse(SpellChecker.IsLanguageSupported("zz-zz")); + } + /// + /// Defines the test method IsPlatformSupportedTest. + /// + [TestMethod] + public void IsPlatformSupportedTest() => Assert.IsTrue(SpellChecker.IsPlatformSupported()); + + /// + /// Defines the test method LanguageIdTest. + /// + [TestMethod] + public void LanguageIdTest() + { + using var spell = new SpellChecker("en-AU"); Assert.AreEqual(spell.LanguageTag, "en-AU"); } + /// + /// Defines the test method MultiSessionTest. + /// [TestMethod] - public void DoubleDisposeTest() + public void MultiSessionTest() { - var spell = new SpellChecker("en-AU"); + var spell1 = new SpellChecker("en-us"); + using var spell2 = new SpellChecker("fr-fr"); + var examples1 = spell1.Suggestions("doog").ToList(); + spell1.Dispose(); + var examples2 = spell2.Suggestions("doog").ToList(); - spell.Dispose(); - spell.Dispose(); // No error + Assert.AreEqual(examples1.Count(), 10); + Assert.AreEqual(examples2.Count(), 2); + } + + /// + /// Defines the test method SuggestionsTest. + /// + [TestMethod] + public void SuggestionsTest() + { + using var spell = new SpellChecker(); + var examples = spell.Suggestions("manle"); + + Assert.IsTrue(examples.Any()); + } + + /// + /// Defines the test method SupportedLanguagesTest. + /// + [TestMethod] + public void SupportedLanguagesTest() => Assert.IsTrue(SpellChecker.SupportedLanguages.Any()); + + /// + /// Defines the test method UnsupportedLangTest. + /// + [TestMethod] + [ExpectedException(typeof(ArgumentException))] + public void UnsupportedLangTest() + { + using (var spell = new SpellChecker("zz-zz")) + { + } } } } diff --git a/src/SpellCheck.sln b/src/SpellCheck.sln index f1e4922..dcb477b 100644 --- a/src/SpellCheck.sln +++ b/src/SpellCheck.sln @@ -1,11 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29318.209 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpellCheck", "SpellCheck\SpellCheck.csproj", "{6D5E0752-9F30-413B-9D9C-6B65850606C7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpellCheck", "SpellCheck\SpellCheck.csproj", "{EF1D68F3-B6BC-4A7F-A69A-48A8360BF0A8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpellCheck.Tests", "SpellCheck.Tests\SpellCheck.Tests.csproj", "{68057238-23BD-470C-980F-C5DADDF62E4E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpellCheck.Tests", "SpellCheck.Tests\SpellCheck.Tests.csproj", "{4A089F22-37DD-4828-8D62-F9F1D09EE200}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{419D4FF8-A32B-4482-8924-D19BAB937530}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -13,16 +15,19 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6D5E0752-9F30-413B-9D9C-6B65850606C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6D5E0752-9F30-413B-9D9C-6B65850606C7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6D5E0752-9F30-413B-9D9C-6B65850606C7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6D5E0752-9F30-413B-9D9C-6B65850606C7}.Release|Any CPU.Build.0 = Release|Any CPU - {68057238-23BD-470C-980F-C5DADDF62E4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {68057238-23BD-470C-980F-C5DADDF62E4E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {68057238-23BD-470C-980F-C5DADDF62E4E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {68057238-23BD-470C-980F-C5DADDF62E4E}.Release|Any CPU.Build.0 = Release|Any CPU + {EF1D68F3-B6BC-4A7F-A69A-48A8360BF0A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EF1D68F3-B6BC-4A7F-A69A-48A8360BF0A8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EF1D68F3-B6BC-4A7F-A69A-48A8360BF0A8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EF1D68F3-B6BC-4A7F-A69A-48A8360BF0A8}.Release|Any CPU.Build.0 = Release|Any CPU + {4A089F22-37DD-4828-8D62-F9F1D09EE200}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A089F22-37DD-4828-8D62-F9F1D09EE200}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A089F22-37DD-4828-8D62-F9F1D09EE200}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A089F22-37DD-4828-8D62-F9F1D09EE200}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {035BB16B-A8A0-45BA-91FA-F668B81235A2} + EndGlobalSection EndGlobal diff --git a/src/SpellCheck/License.md b/src/SpellCheck/License.md new file mode 100644 index 0000000..d377631 --- /dev/null +++ b/src/SpellCheck/License.md @@ -0,0 +1 @@ +The MIT License (MIT) Copyright (c) 2015 Bruce Bowyer-Smyth Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/src/SpellCheck/Properties/AssemblyInfo.cs b/src/SpellCheck/Properties/AssemblyInfo.cs deleted file mode 100644 index 9bf7772..0000000 --- a/src/SpellCheck/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SpellCheck")] -[assembly: AssemblyDescription("Managed wrapper for the Microsoft Spell Checking API")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SpellCheck")] -[assembly: AssemblyCopyright("Copyright © Bruce Bowyer-Smyth")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: CLSCompliant(true)] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("b47f933e-acfc-4a28-8187-c27b38e97050")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/SpellCheck/RecommendedAction.cs b/src/SpellCheck/RecommendedAction.cs index 73b511a..4fa7221 100644 --- a/src/SpellCheck/RecommendedAction.cs +++ b/src/SpellCheck/RecommendedAction.cs @@ -1,4 +1,7 @@ - +// +// Copyright © Bruce Bowyer-Smyth +// + namespace PlatformSpellCheck { /// diff --git a/src/SpellCheck/SpellCheck.csproj b/src/SpellCheck/SpellCheck.csproj index 1195ebf..80767f8 100644 --- a/src/SpellCheck/SpellCheck.csproj +++ b/src/SpellCheck/SpellCheck.csproj @@ -1,63 +1,52 @@ - - - + + - Debug - AnyCPU - {6D5E0752-9F30-413B-9D9C-6B65850606C7} - Library - Properties + netstandard2.0 + en-US + Managed wrapper for the Microsoft Spell Checking API + Copyright © Bruce Bowyer-Smyth + true + Bruce Bowyer-Smyth + git + https://github.com/bbowyersmyth/SpellCheck + PlatformSpellCheck + Spell Check + http://github.com/bbowyersmyth/spellcheck + spell checker check spell-check spell-checker spellchecker spellcheck suggestion + UserDictionariesRegistrar, LanguageTag, Add, and AutoCorrect + + License.md PlatformSpellCheck PlatformSpellCheck - v4.0 - 512 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - MinimumRecommendedRules.ruleset - bin\Debug\PlatformSpellCheck.xml + + + C:\Users\WilliamForney\OneDrive - IMPROVGROUP LLC\Documents\GitHub\SpellCheck\src\SpellCheck\bin\$(Configuration)\PlatformSpellCheck.xml - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\PlatformSpellCheck.xml + + + C:\Users\WilliamForney\OneDrive - IMPROVGROUP LLC\Documents\GitHub\SpellCheck\src\SpellCheck\bin\$(Configuration)\PlatformSpellCheck.xml + + + + + ..\..\lib\MsSpellCheckLib.dll - True - - - - - - - + + + + True + + + + - - - - - + - - - \ No newline at end of file + + diff --git a/src/SpellCheck/SpellChecker.cs b/src/SpellCheck/SpellChecker.cs index 0f5c294..b706466 100644 --- a/src/SpellCheck/SpellChecker.cs +++ b/src/SpellCheck/SpellChecker.cs @@ -1,27 +1,39 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Runtime.InteropServices; +// +// Copyright © Bruce Bowyer-Smyth +// namespace PlatformSpellCheck { + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Runtime.InteropServices; + + using MsSpellCheckLib; + /// /// The Spell Checking API permits developers to consume spell checker capability to check text, and get suggestions + /// Implements the /// + /// public class SpellChecker : IDisposable { - private MsSpellCheckLib.ISpellChecker _spellChecker; + /// + /// The spell checker + /// + private ISpellChecker spellChecker; /// + /// Initializes a new instance of the class. /// Creates a spell checker that supports the current UI language /// public SpellChecker() { - var factory = new MsSpellCheckLib.SpellCheckerFactory(); + var factory = new SpellCheckerFactory(); try { - _spellChecker = factory.CreateSpellChecker(CultureInfo.CurrentUICulture.Name); + this.spellChecker = factory.CreateSpellChecker(CultureInfo.CurrentUICulture.Name); } finally { @@ -30,18 +42,25 @@ public SpellChecker() } /// + /// Initializes a new instance of the class. /// Creates a spell checker that supports the specified language /// - /// can be called to determine if languageTag is supported - /// languageTag is an empty string, or there is no spell checker available for languageTag - /// A BCP47 language tag that identifies the language for the requested spell checker + /// + /// A BCP47 language tag that identifies the language for the requested spell checker + /// + /// + /// languageTag is an empty string, or there is no spell checker available for languageTag + /// + /// + /// can be called to determine if languageTag is supported + /// public SpellChecker(string languageTag) { - var factory = new MsSpellCheckLib.SpellCheckerFactory(); + var factory = new SpellCheckerFactory(); try { - _spellChecker = factory.CreateSpellChecker(languageTag); + this.spellChecker = factory.CreateSpellChecker(languageTag); } finally { @@ -50,62 +69,42 @@ public SpellChecker(string languageTag) } /// - /// Determines if the current operating system is supports the Windows Spell Checking API + /// Finalizes an instance of the class. /// - /// true if OS is supported, false otherwise - public static bool IsPlatformSupported() - { - return Environment.OSVersion.Version > new Version(6, 2); - } - - /// - /// Determines if the specified language is supported by a registered spell checker - /// - /// A BCP47 language tag that identifies the language for the requested spell checker - /// true if supported, false otherwise - public static bool IsLanguageSupported(string languageTag) + ~SpellChecker() { - var factory = new MsSpellCheckLib.SpellCheckerFactory(); - - try - { - return (factory.IsSupported(languageTag) != 0); - } - finally - { - Marshal.ReleaseComObject(factory); - } + this.Dispose(false); } /// /// Gets the set of BCP47 language tags supported by the spell checker /// + /// The supported languages. public static IEnumerable SupportedLanguages { get { - var factory = new MsSpellCheckLib.SpellCheckerFactory(); - MsSpellCheckLib.IEnumString langs = null; + var factory = new SpellCheckerFactory(); + IEnumString languages = null; try { - langs = factory.SupportedLanguages; + languages = factory.SupportedLanguages; - string currentLang; - uint fetched; - - langs.RemoteNext(1, out currentLang, out fetched); + languages.RemoteNext(1, out var currentLang, out var fetched); while (currentLang != null) { yield return currentLang; - langs.RemoteNext(1, out currentLang, out fetched); + languages.RemoteNext(1, out currentLang, out fetched); } } finally { - if (langs != null) - Marshal.ReleaseComObject(langs); + if (languages != null) + { + Marshal.ReleaseComObject(languages); + } Marshal.ReleaseComObject(factory); } @@ -115,61 +114,47 @@ public static IEnumerable SupportedLanguages /// /// Gets the BCP47 language tag this instance of the spell checker supports /// - public string LanguageTag + /// The language tag. + public string LanguageTag => this.spellChecker.languageTag; + + /// + /// Determines if the specified language is supported by a registered spell checker + /// + /// A BCP47 language tag that identifies the language for the requested spell checker + /// true if supported, false otherwise + public static bool IsLanguageSupported(string languageTag) { - get + var factory = new SpellCheckerFactory(); + + try { - return _spellChecker.languageTag; + return factory.IsSupported(languageTag) != 0; + } + finally + { + Marshal.ReleaseComObject(factory); } } + /// + /// Determines if the current operating system is supports the Windows Spell Checking API + /// + /// true if OS is supported, false otherwise + public static bool IsPlatformSupported() => Environment.OSVersion.Version > new Version(6, 2); + /// /// Treats the provided word as though it were part of the original dictionary. /// The word will no longer be considered misspelled, and will also be considered as a candidate for suggestions. /// - /// - public void Add(string word) - { - _spellChecker.Add(word); - } + /// The word. + public void Add(string word) => this.spellChecker.Add(word); /// /// Causes occurrences of one word to be replaced by another /// - /// The incorrectly spelled word to be autocorrected + /// The incorrectly spelled word to be auto-corrected /// The correctly spelled word that should replace from - public void AutoCorrect(string from, string to) - { - _spellChecker.AutoCorrect(from, to); - } - - /// - /// Retrieves spelling suggestions for the supplied text - /// - /// The word or phrase to get suggestions for - /// The list of suggestions - public IEnumerable Suggestions(string word) - { - var suggestions = _spellChecker.Suggest(word); - - try - { - string currentSuggestion; - uint fetched; - - suggestions.RemoteNext(1, out currentSuggestion, out fetched); - - while (currentSuggestion != null) - { - yield return currentSuggestion; - suggestions.RemoteNext(1, out currentSuggestion, out fetched); - } - } - finally - { - Marshal.ReleaseComObject(suggestions); - } - } + public void AutoCorrect(string from, string to) => this.spellChecker.AutoCorrect(from, to); /// /// Checks the spelling of the supplied text and returns a collection of spelling errors @@ -178,8 +163,8 @@ public IEnumerable Suggestions(string word) /// The results of spell checking public IEnumerable Check(string text) { - var errors = _spellChecker.Check(text); - MsSpellCheckLib.ISpellingError currentError = null; + var errors = this.spellChecker.Check(text); + ISpellingError currentError = null; try { @@ -189,26 +174,26 @@ public IEnumerable Check(string text) switch (currentError.CorrectiveAction) { - case MsSpellCheckLib.CORRECTIVE_ACTION.CORRECTIVE_ACTION_DELETE: + case CORRECTIVE_ACTION.CORRECTIVE_ACTION_DELETE: action = RecommendedAction.Delete; break; - case MsSpellCheckLib.CORRECTIVE_ACTION.CORRECTIVE_ACTION_GET_SUGGESTIONS: + case CORRECTIVE_ACTION.CORRECTIVE_ACTION_GET_SUGGESTIONS: action = RecommendedAction.GetSuggestions; break; - case MsSpellCheckLib.CORRECTIVE_ACTION.CORRECTIVE_ACTION_REPLACE: + case CORRECTIVE_ACTION.CORRECTIVE_ACTION_REPLACE: action = RecommendedAction.Replace; break; } - yield return new SpellingError() - { - StartIndex = currentError.StartIndex, - Length = currentError.Length, - RecommendedAction = action, - RecommendedReplacement = currentError.Replacement - }; + yield return new SpellingError + { + StartIndex = currentError.StartIndex, + Length = currentError.Length, + RecommendedAction = action, + RecommendedReplacement = currentError.Replacement + }; Marshal.ReleaseComObject(currentError); } @@ -216,21 +201,14 @@ public IEnumerable Check(string text) finally { if (currentError != null) + { Marshal.ReleaseComObject(currentError); + } Marshal.ReleaseComObject(errors); } } - /// - /// Ignores the provided word for the rest of this session - /// - /// The word to ignore - public void Ignore(string word) - { - _spellChecker.Ignore(word); - } - /// /// Disposes resources used by SpellChecker /// @@ -241,20 +219,47 @@ public void Dispose() } /// - /// Disposes resources used by SpellChecker + /// Ignores the provided word for the rest of this session /// - ~SpellChecker() + /// The word to ignore + public void Ignore(string word) => this.spellChecker.Ignore(word); + + /// + /// Retrieves spelling suggestions for the supplied text + /// + /// The word or phrase to get suggestions for + /// The list of suggestions + public IEnumerable Suggestions(string word) { - this.Dispose(false); + var suggestions = this.spellChecker.Suggest(word); + + try + { + suggestions.RemoteNext(1, out var currentSuggestion, out var fetched); + + while (currentSuggestion != null) + { + yield return currentSuggestion; + suggestions.RemoteNext(1, out currentSuggestion, out fetched); + } + } + finally + { + Marshal.ReleaseComObject(suggestions); + } } - private void Dispose(bool disposing) + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool disposing) { - if (_spellChecker != null) + if (this.spellChecker != null) { - Marshal.ReleaseComObject(_spellChecker); - _spellChecker = null; + Marshal.ReleaseComObject(this.spellChecker); + this.spellChecker = null; } } } -} +} \ No newline at end of file diff --git a/src/SpellCheck/SpellingError.cs b/src/SpellCheck/SpellingError.cs index e2e2215..6e96b0e 100644 --- a/src/SpellCheck/SpellingError.cs +++ b/src/SpellCheck/SpellingError.cs @@ -1,4 +1,7 @@ - +// +// Copyright © Bruce Bowyer-Smyth +// + namespace PlatformSpellCheck { /// @@ -9,21 +12,25 @@ public class SpellingError /// /// Gets the position in the checked text where the error begins /// + /// The start index. public long StartIndex { get; internal set; } /// /// Gets the length of the erroneous text /// + /// The length. public long Length { get; internal set; } /// /// Indicates which corrective action should be taken for the spelling error /// + /// The recommended action. public RecommendedAction RecommendedAction { get; internal set; } /// /// Gets the text to use as replacement text when the corrective action is replace /// + /// The recommended replacement. public string RecommendedReplacement { get; internal set; } } } diff --git a/src/SpellCheck/UserDictionariesRegistrar.cs b/src/SpellCheck/UserDictionariesRegistrar.cs index 9b6b89b..2cc2321 100644 --- a/src/SpellCheck/UserDictionariesRegistrar.cs +++ b/src/SpellCheck/UserDictionariesRegistrar.cs @@ -1,45 +1,47 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; +// +// Copyright © Bruce Bowyer-Smyth +// namespace PlatformSpellCheck { + using System; + using System.Runtime.InteropServices; + /// /// Manages the registration of user dictionaries + /// Implements the /// + /// public class UserDictionariesRegistrar : IDisposable { - private MsSpellCheckLib.IUserDictionariesRegistrar _registrar; + /// + /// The registrar + /// + private MsSpellCheckLib.IUserDictionariesRegistrar registrar; /// /// Maintains user dictionaries /// - public UserDictionariesRegistrar() - { - _registrar = (MsSpellCheckLib.IUserDictionariesRegistrar)new MsSpellCheckLib.SpellCheckerFactory(); - } + public UserDictionariesRegistrar() => this.registrar = + (MsSpellCheckLib.IUserDictionariesRegistrar)new MsSpellCheckLib.SpellCheckerFactory(); /// /// Registers a file to be used as a user dictionary for the current user, until unregistered /// /// The path of the dictionary file to be registered /// The language for which this dictionary should be used. If left empty, it will be used for any language - public void RegisterUserDictionary(string dictionaryPath, string languageTag) - { - _registrar.RegisterUserDictionary(dictionaryPath, languageTag); - } + public void RegisterUserDictionary(string dictionaryPath, string languageTag) => + this.registrar.RegisterUserDictionary(dictionaryPath, languageTag); /// /// Unregisters a previously registered user dictionary. The dictionary will no longer be used by the spell checking functionality. /// /// The path of the dictionary file to be unregistered - /// The language for which this dictionary was used. It must match the language passed to - public void UnregisterUserDictionary(string dictionaryPath, string languageTag) - { - _registrar.UnregisterUserDictionary(dictionaryPath, languageTag); - } + /// + /// The language for which this dictionary was used. It must match the language passed to + /// + public void UnregisterUserDictionary(string dictionaryPath, string languageTag) => + this.registrar.UnregisterUserDictionary(dictionaryPath, languageTag); /// /// Disposes resources used by UserDictionariesRegistrar @@ -58,12 +60,16 @@ public void Dispose() this.Dispose(false); } - private void Dispose(bool disposing) + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool disposing) { - if (_registrar != null) + if (this.registrar != null) { - Marshal.ReleaseComObject(_registrar); - _registrar = null; + Marshal.ReleaseComObject(this.registrar); + this.registrar = null; } } }