Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.35 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to make the below code generic?
  2. private int SaveRecord(PartnerViewLog partnerViewLog, PortalConstant.DataSourceType DataSourceType, Func<IDataAccess, PartnerViewLog, int> chooseSelector)
  3.             {
  4.                 int results = -1;
  5.  
  6.                 var dataPlugin = DataPlugins.FirstOrDefault(i => i.Metadata["SQLMetaData"].ToString() == DataSourceType.EnumToString());
  7.  
  8.                 if (dataPlugin != null)
  9.                 {
  10.                     results = chooseSelector(dataPlugin.Value, partnerViewLog);
  11.                 }
  12.                 return results;
  13.             }
  14.        
  15. public int SavePartnerViewLog(PartnerViewLog partnerViewLog, PortalConstant.DataSourceType DataSourceType)
  16.         {
  17.             return SaveRecord(partnerViewLog, DataSourceType, (i, u) => i.SavePartnerViewLog(partnerViewLog));
  18.         }
  19.        
  20. private int SaveRecord<T>(T record, PortalConstant.DataSourceType dataSourceType, Func<IDataAccess, T, int> chooseSelector)
  21. {
  22.     int results = -1;
  23.  
  24.     var dataPlugin = DataPlugins.FirstOrDefault(i => i.Metadata["SQLMetaData"].ToString() == dataSourceType.EnumToString());
  25.  
  26.     if (dataPlugin != null)
  27.     {
  28.         results = chooseSelector(dataPlugin.Value, record);
  29.     }
  30.  
  31.     return results;
  32. }
  33.        
  34. private int SaveRecord<T>(T partnerViewLog, PortalConstant.DataSourceType dataSourceType, Func<IDataAccess, T, int> chooseSelector)
  35. {
  36.     ...
  37. }