我有
下的方法 private int SaveRecord(PartnerViewLog partnerViewLog, PortalConstant.DataSourceType DataSourceType, Func<IDataAccess, PartnerViewLog, int> chooseSelector)
{
int results = -1;
var dataPlugin = DataPlugins.FirstOrDefault(i => i.Metadata["SQLMetaData"].ToString() == DataSourceType.EnumToString());
if (dataPlugin != null)
{
results = chooseSelector(dataPlugin.Value, partnerViewLog);
}
return results;
}
我在
下调用它public int SavePartnerViewLog(PartnerViewLog partnerViewLog, PortalConstant.DataSourceType DataSourceType)
{
return SaveRecord(partnerViewLog, DataSourceType, (i, u) => i.SavePartnerViewLog(partnerViewLog));
}
可以想象出PartnerViewLog是一个类。现在我想把函数SaveRecord作为通用的,其中类名可以是什么?
怎么做?
答案 0 :(得分:3)
尝试以下方法:
private int SaveRecord<T>(T record, PortalConstant.DataSourceType dataSourceType, Func<IDataAccess, T, int> chooseSelector)
{
int results = -1;
var dataPlugin = DataPlugins.FirstOrDefault(i => i.Metadata["SQLMetaData"].ToString() == dataSourceType.EnumToString());
if (dataPlugin != null)
{
results = chooseSelector(dataPlugin.Value, record);
}
return results;
}
答案 1 :(得分:1)
private int SaveRecord<T>(T partnerViewLog, PortalConstant.DataSourceType dataSourceType, Func<IDataAccess, T, int> chooseSelector)
{
...
}
其他所有事情都是一样的