2012-05-10 15 views
1

この再帰呼び出しをLINQに変換したいが、最後の2つの条件の実行方法がわからない。これらの最後の2つの条件を追加する方法についてアドバイスしてください。ここで再帰コードをLINQに変換する

private void findGoogleOrganic(HtmlNode node) 
    { 
      if (node.Attributes["class"] != null) 
      { 
       if (node.Attributes["class"].Value.ToString().Contains("r ld")) 
       { 
        String tmp; 
        tmp = node.ParentNode.InnerHtml.ToString(); 
        bool condition1 = false; 
        bool condition2 = false; 

        if (tmp != null) 
        { 
         **condition1 = tmp.Contains("qcp47e"); 
         condition2 = tmp.Contains("r ld");** 
        } 

        **if (condition1 == false && condition2 == true)** 
        { 
         GoogleOrganicResults.Add(new Result(URLGoogleOrganic, Listing, node, SearchEngine.Google, SearchType.Organic, ResultType.Website)); 

        } 
       } 
      } 

       if (node.HasChildNodes) 
       { 
        foreach (HtmlNode children in node.ChildNodes) 
        { 
         findGoogleOrganic(children); 
        } 
       } 
      } 

最後の二つの条件なしの私の最初の試みである:

private void findGoogleOrganicLINQ(HtmlNode node) 
    { 
     var results = node.Descendants() 
      .Where(x => x.Attributes["class"] != null && 
         x.Attributes["class"].Value.Contains("r ld")) 
      .Select(x => new Result(URLGoogleLocal, Listing, x, SearchEngine.Google, SearchType.Local, ResultType.GooglePlaces)); 

     foreach (Result x in results) 
     { 
      GoogleOrganicResults.Add(x); 
     } 
    } 
+0

はhttp://codereview.stackexchange.com –

答えて

0
if(node.HasChildNodes) 
{ 
    node.ChildNodes.ForEach(findGoogleOrganic); 
} 
+0

に、このいずれかを試してみてくださいどのようにこの質問に答えるのでしょうか? –

関連する問題