private static K ExecuteStoredProcedure<K>(string connectionString, string storedProcedure, SqlParameter[] parameters, Func<I, K> readFunction)
實施例的使用通過如下所示:問題用C#」泛型,如何通過輸入和輸出經由函數求
return ExecuteStoredProcedure<SqlDataReader, Dictionary<string, string>>(
connectionString,
"uspSearchStatisticsSelectByTokenPerDayGroupByDate",
parameters,
(reader) =>
{
reader.Read();
int readCount = reader.FieldCount;
Dictionary<string, string> results = new Dictionary<string, string>();
results.Add("FailedRequests", Convert.ToString(reader[5]));
results.Add("TotalRequests", Convert.ToString(reader[4]));
results.Add("AverageResponseTime", Convert.ToString(reader[3]));
return results;
}
);
編譯器回來與
錯誤520的類型或名稱空間名稱'I'找不到(您是否缺少使用指令或裝配參考?)
但我認爲它應該能夠引用?
更新:我試圖去尋找過於一般的東西,並沒有真正需要它。
我已經用下面... private static K ExecuteStoredProcedure<K>(string connectionString, string storedProcedure, SqlParameter[] parameters, Func<SqlDataReader, K> readFunction)
鉭,你剛剛發佈後算出來。給我我幾乎要成爲一個SqlDataReader我可能過於複雜! :) – Jamie 2013-03-16 22:48:34