Skip to content

Instantly share code, notes, and snippets.

@ebello
Created November 20, 2008 19:59
Show Gist options
  • Save ebello/27164 to your computer and use it in GitHub Desktop.
Save ebello/27164 to your computer and use it in GitHub Desktop.
public delegate T MethodExecution<T>(IDataReader reader);
public static List<T> LoadList<T>(IDataReader reader, MethodExecution<T> method)
{
return LoadList<T>(reader, true, method);
}
public static List<T> LoadList<T>(IDataReader reader, bool close_reader, MethodExecution<T> method)
{
List<T> list = new List<T>();
try
{
while (reader.Read())
{
list.Add(method(reader));
}
return list;
}
finally
{
if (close_reader)
reader.Close();
}
}
// to use
IDataReader reader = DbProvider.Instance().GetLanguages();
List<string> languages = DataHelper.LoadList<string>(reader, r => r["culture_code"] as string);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment