Files
Dapper/Dapper.Tests.Performance/SqlDataReaderHelper.cs
Nick Craver 1481c4d379 Tooling and project updates (#1333)
This is a branch cleaning up old `#if` clauses, `.csproj` bits, Linux build compatibility, and a few other tid-bits (broken out by commit).

In general: we're on 3.0 tooling and all previous cruft has been removed.
2019-09-26 19:47:55 -04:00

32 lines
901 B
C#

using System;
using System.Data.SqlClient;
using System.Runtime.CompilerServices;
namespace Dapper.Tests.Performance
{
public static class SqlDataReaderHelper
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string GetNullableString(this SqlDataReader reader, int index)
{
object tmp = reader.GetValue(index);
if (tmp != DBNull.Value)
{
return (string)tmp;
}
return null;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T? GetNullableValue<T>(this SqlDataReader reader, int index) where T : struct
{
object tmp = reader.GetValue(index);
if (tmp != DBNull.Value)
{
return (T)tmp;
}
return null;
}
}
}