Ich habe eine Funktion, die LINQ-Ergebnisse an die Steuerelemente in meinem Formular bindet. Der folgende Code funktioniert, aber ich komme einfach nicht über das Gefühl, dass ich für den Copy/Paste-Aspekt geschlagen werden sollte. Kann mir jemand helfen, was ich tun muss, um das zu desodorieren?Refactoring-Methode, die Steuerelemente an LINQ bindet
Vielen Dank!
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;
}
Danke, das scheint auf dem richtigen Weg zu sein. Meine mag "dieses" nicht. "Extension-Methode kann nur in nicht-generische, nicht verschachtelte statische Klasse deklariert werden" Ideen ?? –
Ja, Sie müssen es in einer statischen Klasse deklarieren. öffentliche statische Klasse MyExtensions {(hier einfügen)} –