1 /* Copyright (c) 2007 Eric Scott Albright
\r
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
4 * of this software and associated documentation files (the "Software"), to deal
\r
5 * in the Software without restriction, including without limitation the rights
\r
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
7 * copies of the Software, and to permit persons to whom the Software is
\r
8 * furnished to do so, subject to the following conditions:
\r
10 * The above copyright notice and this permission notice shall be included in
\r
11 * all copies or substantial portions of the Software.
\r
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
23 using System.Collections.Generic;
\r
27 public sealed class Dictionary : IDisposable
\r
29 private readonly SafeDictionaryHandle _handle;
\r
30 private bool _disposed = false;
\r
31 private DictionaryInfo _info;
\r
33 internal Dictionary(SafeDictionaryHandle handle)
\r
37 throw new ArgumentNullException("handle");
\r
39 if (handle.IsInvalid)
\r
41 throw new ArgumentException("handle is invalid");
\r
46 public DictionaryInfo Information
\r
50 VerifyNotDisposed();
\r
53 InitializeDictionaryInformation();
\r
59 private void InitializeDictionaryInformation()
\r
61 Bindings.enchant_dict_describe(_handle,
\r
62 delegate(DictionaryInfo dictionary)
\r
68 #region IDisposable Members
\r
70 public void Dispose()
\r
73 GC.SuppressFinalize(this);
\r
78 private void Dispose(bool disposing)
\r
84 // dispose-only, i.e. non-finalizable logic
\r
88 // shared (dispose and finalizable) cleanup logic
\r
92 OnDisposed(); // call it here so will throw if someone uses
\r
93 // it because _disposed has been set to true;
\r
98 private void VerifyNotDisposed()
\r
102 throw new ObjectDisposedException("Dictionary");
\r
106 public bool Check(string word)
\r
108 VerifyNotDisposed();
\r
111 throw new ArgumentNullException("word");
\r
113 // result is 0 if correctly spelled, positive if not, negative if error
\r
114 int result = Bindings.enchant_dict_check(_handle, word);
\r
117 string message = Bindings.enchant_dict_get_error(_handle);
\r
118 throw new ApplicationException(message);
\r
120 return result == 0;
\r
123 public ICollection<string> Suggest(string word)
\r
125 VerifyNotDisposed();
\r
128 throw new ArgumentNullException("word");
\r
130 return Bindings.enchant_dict_suggest(_handle, word);
\r
133 public void Add(string word)
\r
135 VerifyNotDisposed();
\r
138 throw new ArgumentNullException("word");
\r
140 Bindings.enchant_dict_add(_handle, word);
\r
143 public void AddToSession(string word)
\r
145 VerifyNotDisposed();
\r
148 throw new ArgumentNullException("word");
\r
150 Bindings.enchant_dict_add_to_session(_handle, word);
\r
153 public bool IsAdded(string word)
\r
155 VerifyNotDisposed();
\r
158 throw new ArgumentNullException("word");
\r
160 return Bindings.enchant_dict_is_added(_handle, word) == 1;
\r
163 public void Remove(string word)
\r
165 VerifyNotDisposed();
\r
168 throw new ArgumentNullException("word");
\r
170 Bindings.enchant_dict_remove(_handle, word);
\r
173 public void RemoveFromSession(string word)
\r
175 VerifyNotDisposed();
\r
178 throw new ArgumentNullException("word");
\r
180 Bindings.enchant_dict_remove_from_session(_handle, word);
\r
183 public bool IsRemoved(string word)
\r
185 VerifyNotDisposed();
\r
188 throw new ArgumentNullException("word");
\r
190 return Bindings.enchant_dict_is_removed(_handle, word) == 1;
\r
193 public void StoreReplacement(string misspelling, string correction)
\r
195 VerifyNotDisposed();
\r
196 if (misspelling == null)
\r
198 throw new ArgumentNullException("misspelling");
\r
200 if (correction == null)
\r
202 throw new ArgumentNullException("correction");
\r
204 Bindings.enchant_dict_store_replacement(_handle, misspelling, correction);
\r
208 /// Occurs when a dictionary is disposed by a call to the Dispose method
\r
210 public event EventHandler Disposed = delegate { };
\r
212 private void OnDisposed()
\r
214 Disposed.Invoke(this, new EventArgs());
\r