2009-08-11 2 views
0

와 wotrking하지, RadComboBoxItemCollection는 IEnumerable을 구현하기 위해 나타납니다하지만 LINQ는 말을 나에게 오류를주고 유지 :RadComboBoxItemCollection 내가 몇 가지 확장 방법을 만드는거야 내가 RadComboBoxItemCollection 일부 오류를 받고 있어요 LINQ

"구현을 찾을 수 없습니다 소스 유형 에 대한 쿼리 패턴 'Telerik.Web.UI.RadComboBoxItemCollection' '찾을 수 없음' 범위 변수 'myItem'의 형식을 명시 적으로 지정하십시오. " 플립 사이드 RadListBoxItemCollection에이 코드

public static bool ContainsValue(this RadComboBoxItemCollection myList, string value) 
{ 
     bool matches = (from myItem in myList where myItem.Value == value select myItem).Count() > 0; 
     return matches; 
} 

에서

public static bool ContainsValue(this IEnumerable<RadListBoxItem> myList, string value) 
{ 
     bool matches = (from myItem in myList where myItem.Value == value select myItem).Count() > 0; 
     return matches; 
} 

내가 IEnumerable을하고 시도 잘 작동이는 LINQ 오류를 해결하지만 난이 오류를 얻을

"인스턴스 인수 : 변환 할 수 없습니다. 'Telerik.Web.UI.RadComboBoxItemCollection'에서 에 'System.Collections.Generic.IEnumerable' "

답변

1

RadComboBoxItemCollection는 제네릭이 아닌 IEnumerable을 인터페이스 (보다는 합리적인 일을하고 IEnumerable을 구현을 구현 < RadComboBoxItem>), 표준 LINQ 작업이 작동하지 않습니다. 먼저 "캐스트"확장 방법을 사용하는 것이다 :

var result = myList.Items.Cast<RadComboBoxItem>(); 

지금 당신이를 훨씬 더 유용는 IEnumerable < RadComboBoxItem> 당신과 멋진 사물의 모든 종류의 할 수있는 : 그러나

public static bool ContainsValue(this RadComboBoxItemCollection myList, string value) 
{ 
     return myList.Items.Cast<RadComboBoxItem>().Count(item => item.Value.Equals(value, StringComparison.Ordinal)) > 0; 
} 

, 나보다 더 많은 경험을 가진 누군가가 아마이 접근법의 수행에 대해 말할 수있을 것이다. 단지 그것을 이전 (사전 LINQ를) 수행에 그것은 RadComboBoxItem에 각 개체를 캐스팅보다 방법이 아니라 성능을 위해 더 좋을 수 있습니다

public static bool ContainsValue(this RadComboBoxItemCollection myList, string value) 
{ 
     foreach (var item in myList) 
      if (item.Value.Equals(value, StringComparison.Ordinal)) 
       return true; 

     return false 
} 
+0

권리, 내가 for 루프, Telerik가 업데이트됩니다를 사용하여 유사한 수정 프로그램을 사용하면 이 문제를 해결할 수있는 권한이 있습니다. –

관련 문제