我有一個綁定源可以綁定到A列表或B列表。取決於如果它是A或B,當我單擊「保存」時,我想調用保存適當的存儲庫的方法。函數返回不同的可能子類的列表
我能創造這個方法來檢查是否有列表是髒並需要保存:
private static bool IsDirty<T>(TList<T> list) where T : IEntity, new()
{
foreach (var entity in list)
{
if (entity.IsDirty)
return true;
}
return false;
}
不過,我有一個問題如下:
var list = CurrentTList<A>();
和
private TList<T> CurrentTList<T>() where T: IEntity, new()
{
switch (currentRatesTable)
{
case RatesTables.A:
return (TList<T>) _bindingSourceMaster.List;
case RatesTables.B:
return (TList<T>) _bindingSourceMaster.List;
default:
return null;
}
}
這是從數據源獲取當前列表的最佳方式嗎?我想避免使用開關,像這樣的,因爲它看起來不正確對我說:
switch (currentRatesTable)
{
case Form1.RatesTables.A:
var list = CurrentTList<A>();
case Form1.RatesTables.B:
var list = CurrentTList<B>();
// ...
}
這聽起來像你真正需要的是一個接口 – Sayse
你打算如何處理返回的'list'?什麼是TList? –
一個TLIST是一個列表 - >公共類從TList:ListBase 其中T:IEntity,新的()和ListBase是 公共抽象類ListBase :的BindingList ,IBindingListView,IBindingList的,IList的,ICloneable,ICloneableEx,IListSource,ITypedList, IDisposable,IComponent,IRaiseItemChangedEvents,IDeserializationCallback –
SerenityNow