Skip to content

Commit

Permalink
Implement conversions in GetFieldValue<T>. Fixes #716
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrainger committed Oct 19, 2019
1 parent f4c1cc0 commit 00199a0
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 6 deletions.
44 changes: 39 additions & 5 deletions src/MySqlConnector/MySql.Data.MySqlClient/MySqlDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,48 @@ public ReadOnlyCollection<DbColumn> GetColumnSchema()

public override T GetFieldValue<T>(int ordinal)
{
if (typeof(T) == typeof(bool))
return (T) (object) GetBoolean(ordinal);
if (typeof(T) == typeof(byte))
return (T) (object) GetByte(ordinal);
if (typeof(T) == typeof(sbyte))
return (T) (object) GetSByte(ordinal);
if (typeof(T) == typeof(short))
return (T) (object) GetInt16(ordinal);
if (typeof(T) == typeof(ushort))
return (T) (object) GetUInt16(ordinal);
if (typeof(T) == typeof(int))
return (T) (object) GetInt32(ordinal);
if (typeof(T) == typeof(uint))
return (T) (object) GetUInt32(ordinal);
if (typeof(T) == typeof(long))
return (T) (object) GetInt64(ordinal);
if (typeof(T) == typeof(ulong))
return (T) (object) GetUInt64(ordinal);
if (typeof(T) == typeof(char))
return (T) (object) GetChar(ordinal);
if (typeof(T) == typeof(decimal))
return (T) (object) GetDecimal(ordinal);
if (typeof(T) == typeof(double))
return (T) (object) GetDouble(ordinal);
if (typeof(T) == typeof(float))
return (T) (object) GetFloat(ordinal);
if (typeof(T) == typeof(string))
return (T) (object) GetString(ordinal);
if (typeof(T) == typeof(DateTime))
return (T) (object) GetDateTime(ordinal);
if (typeof(T) == typeof(DateTimeOffset))
return (T) Convert.ChangeType(GetDateTimeOffset(ordinal), typeof(T));
if (typeof(T) == typeof(TextReader) || typeof(T) == typeof(StringReader))
return (T) (object) GetTextReader(ordinal);
if (typeof(T) == typeof(Stream))
return (T) (object) GetStream(ordinal);
return (T) (object) GetDateTimeOffset(ordinal);
if (typeof(T) == typeof(Guid))
return (T) (object) GetGuid(ordinal);
if (typeof(T) == typeof(MySqlGeometry))
return (T) (object) GetMySqlGeometry(ordinal);
if (typeof(T) == typeof(Stream))
return (T) (object) GetStream(ordinal);
if (typeof(T) == typeof(TextReader) || typeof(T) == typeof(StringReader))
return (T) (object) GetTextReader(ordinal);
if (typeof(T) == typeof(TimeSpan))
return (T) (object) GetTimeSpan(ordinal);

return base.GetFieldValue<T>(ordinal);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Conformance.Tests/Conformance.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AdoNet.Specification.Tests" Version="2.0.0-alpha5" />
<PackageReference Include="AdoNet.Specification.Tests" Version="2.0.0-alpha6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
Expand Down
Loading

0 comments on commit 00199a0

Please sign in to comment.