2017-02-18 4 views
-3

내가 MyFilter는 포스 데이타 유형이다Linq에 Enumerable.Where Func을가

static bool MyFilter(Dictionary<string,string> dict, List<WhereClause> wheres) 
    { 
     if (dict["x"] == "y") 
      return true; 
     else 
      return false; 
    } 

으로 정의된다

var filteredList = posData.Where(x => MyFilter(x, ruleDetail.wheres)).ToList(); 

List<dictionary<string,string>> 

내가 중단 점을 다음과 같은 코드를 가지고있다라고 안한다 MyFilter 함수에서 코드 실행은 결코 이루어지지 않습니다. Wheres 매개 변수를 기반으로 사용자 정의 분석을 수행하기 위해 MyFilter를 찾고 있습니다. 이것은 코드의 일부에 지나지 않습니다. MyFilter가 왜 호출되지 않는지 알아내는 데 도움이됩니까?

+0

(가)''<, 문자열을 문자열>'사전의 컬렉션을 postData'인가 :

나는 (당신 같이 기본적으로 동일)이 코드 이 그것을 시도? –

+1

제쳐두고, 당신 몸의 방법은 단지 다음과 같이 바뀔 수 있습니다 :'return dict [ "x"] == "y";' – itsme86

+0

'posData'는 비어있을 수 있습니까? 그러면 MyFilter()가 호출되지 않습니다. – itsme86

답변

1

코드가 잘 작동하고 예상대로 작동해야합니다. 귀하의 경우에 작동하지 않는 유일한 이유는 posData이 비어 있다면 이므로이 아닌지 확인하십시오.

static void Main() 
{ 
    // create test collection 
    var posData = new List<Dictionary<string,string>>(); 
    var test = new Dictionary<string,string>(); 
    test.Add("x", "y"); 
    posData.Add(test); 

    // call the Where function 
    var filteredList = posData.Where(x => MyFilter(x)).ToList(); 

    Console.WriteLine(filteredList.Count); // outputs "1" 
} 

static bool MyFilter(Dictionary<string,string> dict) 
{ 
    Console.WriteLine("hello"); // outputs "hello" 
    return dict["x"] == "y"; 
}