Skip to content

Instantly share code, notes, and snippets.

@htoooth
Created October 25, 2014 12:37
Show Gist options
  • Select an option

  • Save htoooth/122f0ff596082ccac576 to your computer and use it in GitHub Desktop.

Select an option

Save htoooth/122f0ff596082ccac576 to your computer and use it in GitHub Desktop.
public static class RecordExtensions
{
private static class Cache<T>
{
public static Func<IDataRecord,int, T> Get;
}
static RecordExtensions()
{
Cache<string>.Get = (record, field) => record.GetString(field);
Cache<int>.Get = (record, field) => record.GetInt32(field);
Cache<long>.Get = (record, field) => record.GetInt64(field);
Cache<float>.Get = (record, field) => record.GetFloat(field);
Cache<double>.Get = (record, field) => record.GetDouble(field);
}
public static T Get<T>(this IDataRecord record, int field)
{
return Cache<T>.Get(record, field);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment