mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-18 22:31:08 +08:00
78ed4b2077
One of several moves to make this something we can dev on all platforms and build on Actions for v3 onwards.
32 lines
901 B
C#
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;
|
|
}
|
|
}
|
|
}
|