2016-03-31 1 views
-1

リストから正しいスペルの単語を特定する必要があります。単語が間違っている場合、私はファイルに書き込む。私はクラスのスペルチェッカーを使用し、これは私のコードです:SpellChecker(C#)が単語を間違って定義するのはなぜですか?

public class SpellChecker : IDisposable 
{ 
    System.Type TWord = null; object com_app = null; 

    private static SpellChecker Checker = new SpellChecker(); 
    private SpellChecker() 
    { 
     try 
     { 
      TWord = Type.GetTypeFromProgID("Word.Application"); 
      com_app = Activator.CreateInstance(TWord); 
     } 
     catch { com_app = null; } 
    } 

    public static SpellChecker GetChecker() { return Checker; } 
    public void Dispose() 
    { 
     if (com_app != null) 
     { 
      object[] arg = { null, null, null }; 
      TWord.InvokeMember("Quit", BindingFlags.InvokeMethod, 
       null, com_app, arg); 
      com_app = null; 
     } 
    } 
    public bool CheckWord(string word) 
    { 
     object[] arg = { word }; 
     return (bool)TWord.InvokeMember("CheckSpelling", 
      BindingFlags.InvokeMethod, null, com_app, arg); 
    } 
} 

しかし、同じ言葉で、それは私が(言葉を)リストをセッター場合、異なるの作業やただ一言。 私が見るプロセスのデバッグでは、そのCheckWordが私に本当のことを与えてくれるのですが、別のケースではfalseです。しかし、それは一つの言葉です、私は確かです。

var allWord = GetWords(xdoc); 
      foreach (var word in allWord) 
      { 
       if (!spellChecker.CheckWord(word)) 
       { 
        result.WriteLine(word); 
       } 
      } 
+0

言葉は何ですか? – user1666620

答えて

0

実現しました。場合によっては、CheckWordが私に間違った答えを与えます。たとえば、私はロシア語と英語の単語を確認する必要があります。リストリスト= List(){"GSM \ MPG4 \ LTE"、 "Привет"}を指定すると、リストの最初の単語にはそれがtrueが返されますが、2番目の単語はfalseになります。