Created
November 20, 2008 19:59
-
-
Save ebello/27164 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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