2012-12-09 42 views
0

我正在構建通用的共享點DALL,所以我需要幫助。 我不知道這是否適用,但它邏輯上它必須是。通用類的調用方法

我的問題是我的gr8 TTL不確定他需要使用什麼數據源:S(SQL或SharePoint列表),他需要爲項目開始開發。

所以我需要建立DAL作爲SP列表是我的數據源,所以未來的變化將最小化。

現在我已經是baseDAL包括所有常見的操作,例如刪除,GETALL ,,,等

myBase DAL類現在類似

public class BaseDAL<T> where T : BaseInfo,new() 
{ 
    public virtual List<T> GetAllItem() 
{ 
    //code to read from any data source and return data 

} 
public virtual Boolean Delete(T entity) 
{ 
    int entityID = ((BaseInfo)entity).ID; 
    deleteEntity(entityID); 
} 

}

和我有baseInfo作爲主要的業務對象實體。

,並讓說,我有兩個實體企業(員工,學生)和兩個DAL一個員工,一個用於學生

所以我在想什麼正在實施getAllItem代碼returnes基於在T型所有項目,所以代碼可能看起來像波紋管在baseDAL

public virtual List<T> GetAllItem() 
{ 

    SPListItemCollection items = //code to read from list please note that list name saved in baseInfo object 
    T.getBusinessListItems(items); //toList 

} 

和EmployeeDAL我實現SPListItemCollection之間的映射功能,以企業實體的代碼將被samiliare這個

public virtual List<Employee> getBusinessListItems(SPListItemCollection items) 
{ 

    //loop the items and fill them in list of employee objects 
    return list<Employee> 

} 

希望這個澄清的情況下,我不知道這是寫的方式做到這一點我不是一個技術人員。如果還有其他方法可以做,請幫忙。

+0

我不能理解你的問題..你想要做什麼... – Anirudha

+0

我已經添加一個C#的標籤,因爲我認爲這是C#。如果不是這樣,請更改它。 –

+0

特別是'T.toList'部分!你想在這裏做什麼...... – Anirudha

回答

0

不知道這是否是你想要的,但它可能會幫助:

object someDal = ...; //you don't know the exact type 
var list = ((dynamic)someDal).GetAllItem(); 

C#動態已經解決了這個問題你。

+0

謝謝你,但我認爲現在的實際實施需要是EmployeeDAL,這是我不需要做的。我需要將數據放在BaseDAL上的實現,並且baseDAL將基於T的轉換爲業務類型。 – Moe

0

最後我管理具有相同的結構,我有我用下面的代碼,我認爲它稱爲反射我不知道這樣做,, ,,

public virtual List<T> GetAllItems(Type DalType)//this is baseDAL 
{ 
    MethodInfo methodInfo = DalType.GetMethod("ConvertToBusinessEntities"); 
    object[] parametersArray = new object[] { itemCollection }; 
    object classInstance = Activator.CreateInstance(DalType, null); 
    return (List<T>)methodInfo.Invoke(classInstance, parametersArray); 
} 

我只需要通過DalType知道從哪個類調用該方法,如果確保所有DAL都實現了ConvertToBusinessEntities方法,則該代碼將起作用,該方法可以通過接口進行管理。 我希望這種結構的代碼足夠強大... 它不是死衚衕,所有:) ,,,