LINQ 결과를 양식의 컨트롤에 바인딩하는 함수가 있습니다. 아래의 코드는 작동하지만 필자는 복사/붙여 넣기 측면에서 부딪히는 느낌을 극복 할 수 없습니다. 이 냄새 제거를 위해 내가해야 할 일을 도와 줄 수 있습니까?컨트롤을 LINQ에 바인딩하는 리팩터링 메서드
감사합니다! 다음
IQueryable<string> GetDescriptions(int cat)
{
return from x in caseNotesItems
where x.CategoryID == cat
select x.ItemDescription;
}
그리고 :
private void BindDataToForm()
{
// Bind data to form
CaseNotesDataContext db = new CaseNotesDataContext();
Table<CN_MaintItem> caseNotesItems = db.GetTable<CN_MaintItem>();
// For each object
var contactType = from cType in caseNotesItems
where cType.CategoryID == 2
select cType.ItemDescription;
chkContactType.DataSource = contactType;
var contactLocation = from cLocation in caseNotesItems
where cLocation.CategoryID == 3
select cLocation.ItemDescription;
lkuContactLocation.Properties.DataSource = contactLocation;
var contactMethod = from cMethod in caseNotesItems
where cMethod.CategoryID == 4
select cMethod.ItemDescription;
lkuContactMethod.Properties.DataSource = contactMethod;
var contactWith = from cWith in caseNotesItems
where cWith.CategoryID == 5
select cWith.ItemDescription;
chkContactWith.DataSource = contactWith;
var domains = from d in caseNotesItems
where d.CategoryID == 6
select d.ItemDescription;
chkDomains.DataSource = domains;
}
고마워, 이건 바른 길에있는 것 같아. 내 것은 "이"를 좋아하지 않습니다. "확장 메서드는 비 제네릭, 중첩되지 않은 정적 클래스에서만 선언 할 수 있습니다." 아이디어? –
그래, 정적 클래스에서 선언해야합니다. public static class MyExtensions {(여기에 넣으십시오)} –