2012-02-21 15 views
-1

このメソッドは、OSVersionというクラスの一部です。私はそれがうまく動作しますが、私はコンソールアプリケーションでこれをテストします。 Countは現在のコンテキストに存在しません。誰でもこの光を当ててください。名前の数が現在のコンテキストに存在しません

public static bool OperatingSystemVersionGet() 
     { 
      XmlDocument xlDoc = new XmlDocument(); 
      string sfile = 
       @"C:\dev\4.6\RTM\R1\Install\SetupManager\SourceCode.SetupManager\SourceCode.SetupManager\Configs\blackpearl\Product.config"; 

      xlDoc.Load(sfile); 
      XmlNodeList nodeList = xlDoc.SelectNodes("//dependancy"); 

      List<string> compareList = new List<string>(); 

      string osv = Environment.OSVersion.VersionString; 

      int firstIndex = osv.IndexOf(' '); 
      int secondIndex = osv.IndexOf(' ', firstIndex + 1); 
      int thirdIndex = osv.IndexOf(' ', secondIndex + 1); 

      String osName = osv.Substring(0, thirdIndex); 
      String majorVersion = osv.Substring(thirdIndex + 1, 1); 
      String minorVersion = osv.Substring(thirdIndex + 3, 1); 

      bool isIn = false; 

      if (nodeList != null) 
       foreach (XmlNode node in nodeList) 
       { 
        try 
        { 

          string type = node.Attributes["type"].Value; 
          string name = node.Attributes["name"].Value; 
          string feat = node.Attributes["featureversion"].Value; 

          String[] versionPart = feat.Split('.'); 

          string second = versionPart[1]; 
          string third = versionPart[2]; 

           if (type == "Windows") 
           { 
            if((name == osName) && ((second == majorVersion) && (third == minorVersion))) 
            { 
             compareList.Add(name); 
            } 

           } 


        } 
        catch(NullReferenceException ex) 
        { 
         //nullReferenceException handled here 
        } 
       } 

      if(compareList.Count == 0) 
      { 
       isIn = true; 
      } 
      else 
      { 
       isIn = false; 
      } 
      return isIn; 

     } 
+0

compareListを初期化する場所が表示されません。しかし、 'compareList'リストの' Count'要素にアクセスしようとしているかのように見えます。代わりに '.size()'を探していますか? – PenguinCoder

+1

returnを "return compareList.Count> 0"にすることができる点を除いて、問題はありません。 – alexsuslin

+0

@PenguinCoder:10行目の 'compareList'を初期化し、' Count'は 'List'の正しいプロパティです。しかし、 'size'メソッドはありません。 –

答えて

3

あなたは、コンパイル時に

はあなたのソリューションをきれいにし、それを再構築しようとするあなたがこれを受け取ることを言います。

エラーは表示されず、現在のプロジェクトで自分の関数のコピーを作成しましたが、エラーなくコンパイルできます。

+0

プロジェクト内のいくつかのメソッドは、継続的に私のxmlファイルを書いていました。少し微調整した後、このメソッドはうまくいくようです。私には分かりませんが、今はうまくいきます。 Thanx – p0enkie

0

あなたのwinformsアプリケーションのソースファイルの一番上には、確かにusing System.Collections.Genericがありません。

+0

私は最初からそれを持っていました。 – p0enkie

関連する問題