コード例 #1
0
        /// <summary>Returns suggested spellings for a word.</summary>
        public string[] Suggest(string word)
        {
            var suggestions = new List <string>();

            int    ptrSize = Marshal.SizeOf(typeof(IntPtr));
            IntPtr slst    = Marshal.AllocHGlobal(ptrSize);
            int    count   = HunspellInterop.Hunspell_suggest(handle, slst, word);

            if (count > 0)
            {
                IntPtr sa = Marshal.ReadIntPtr(slst);
                for (int i = 0;
                     i < count;
                     ++i)
                {
                    IntPtr sp         = Marshal.ReadIntPtr(sa, i * ptrSize);
                    string suggestion = Marshal.PtrToStringAuto(sp);
                    suggestions.Add(suggestion);
                }
                HunspellInterop.Hunspell_free_list(handle, slst, count);
            }

            Marshal.FreeHGlobal(slst);

            return(suggestions.ToArray());
        }