Skip to content

MySql.Data

Benn Benson edited this page Jan 14, 2019 · 1 revision

MySql.Data

public static class MySqlExtensions
{
    private static readonly ValueExtractor _extractor = ValueExtractor.Create(config =>
    {
        config.UseNullTester(obj => obj is DBNull);

        config.UseConverter(ExtractionConverters.DualTypeConverterWithFallbackImpl);
    });

    public static T Column<T>(this MySqlDataReader reader, int i)
    {
        if (reader is null)
            throw new ArgumentNullException(nameof(reader));

        return UnboxT<T>.Unbox(reader.GetValue(i));
    }

    public static T Column<T>(this MySqlDataReader reader, string name)
    {
        if (reader is null)
            throw new ArgumentNullException(nameof(reader));

        return UnboxT<T>.Unbox(reader.GetValue(reader.GetOrdinal(name)));
    }

    public static T GetValue<T>(this MySqlParameter parameter)
    {
        if (parameter is null)
            throw new ArgumentNullException(nameof(parameter));

        return UnboxT<T>.Unbox(parameter.Value);
    }
}
Clone this wiki locally