Skip to content

Instantly share code, notes, and snippets.

@bgrainger
Last active October 5, 2020 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgrainger/33c4f9d573d778c355aebfae3bcd4fc3 to your computer and use it in GitHub Desktop.
Save bgrainger/33c4f9d573d778c355aebfae3bcd4fc3 to your computer and use it in GitHub Desktop.
void Main()
{
using (var writer = new StreamWriter(@"GetValueConversionTestBase.g.cs"))
{
writer.WriteLine("using System;");
writer.WriteLine("using System.CodeDom.Compiler;");
writer.WriteLine("using System.Data;");
writer.WriteLine("using System.Threading.Tasks;");
writer.WriteLine("using Xunit;");
writer.WriteLine("");
writer.WriteLine("namespace AdoNet.Specification.Tests");
writer.WriteLine("{");
writer.WriteLine("\t[GeneratedCode(\"https://gist.github.com/bgrainger/33c4f9d573d778c355aebfae3bcd4fc3\", \"1\")]");
writer.WriteLine("\tpublic abstract partial class GetValueConversionTestBase<TFixture>");
writer.Write("\t{");
foreach (var methodName in s_methods)
{
foreach (var dbType in s_dbTypes)
{
foreach (var magnitude in new[] { "Null", "Empty", "Zero", "One", "Minimum", "Maximum" })
{
var key = $"{dbType}/{magnitude}/{methodName}";
s_expected.TryGetValue(key, out var expected);
if (expected == null)
s_expected.TryGetValue($"{dbType}/{magnitude}/*", out expected);
if (expected == null)
s_expected.TryGetValue($"{dbType}/*/{methodName}", out expected);
if (expected == "Ignore")
continue;
if (expected == null)
{
$"{key} not handled".Dump();
continue;
}
var throws = expected == "Overflow" || expected == "Null" || expected == "InvalidCast";
writer.WriteLine();
writer.WriteLine("\t\t[SkippableFact]");
writer.Write($"\t\tpublic virtual void Get{methodName}{(throws ? "_throws" : "")}_for_{magnitude.ToLowerInvariant()}_{dbType}()");
if (expected == "Overflow")
writer.WriteLine($" => TestException(DbType.{dbType}, ValueKind.{magnitude}, x => x.Get{methodName}(0), typeof(OverflowException));");
else if (expected == "Null")
writer.WriteLine($" => TestException(DbType.{dbType}, ValueKind.{magnitude}, x => x.Get{methodName}(0), Fixture.NullValueExceptionType);");
else if (expected == "InvalidCast")
writer.WriteLine($" => TestException(DbType.{dbType}, ValueKind.{magnitude}, x => x.Get{methodName}(0), typeof(InvalidCastException));");
else
writer.WriteLine($" => TestGetValue(DbType.{dbType}, ValueKind.{magnitude}, x => x.Get{methodName}(0), {expected});");
writer.WriteLine();
writer.WriteLine("\t\t[SkippableFact]");
var typeName = s_methodToType[methodName];
writer.Write($"\t\tpublic virtual void Get{methodName}{(throws ? "_throws" : "")}_for_{magnitude.ToLowerInvariant()}_{dbType}_with_GetFieldValue()");
if (expected == "Overflow")
writer.WriteLine($" => TestException(DbType.{dbType}, ValueKind.{magnitude}, x => x.GetFieldValue<{typeName}>(0), typeof(OverflowException));");
else if (expected == "Null")
writer.WriteLine($" => TestException(DbType.{dbType}, ValueKind.{magnitude}, x => x.GetFieldValue<{typeName}>(0), Fixture.NullValueExceptionType);");
else if (expected == "InvalidCast")
writer.WriteLine($" => TestException(DbType.{dbType}, ValueKind.{magnitude}, x => x.GetFieldValue<{typeName}>(0), typeof(InvalidCastException));");
else
writer.WriteLine($" => TestGetValue(DbType.{dbType}, ValueKind.{magnitude}, x => x.GetFieldValue<{typeName}>(0), {expected});");
writer.WriteLine();
writer.WriteLine("\t\t[SkippableFact]");
writer.Write($"\t\tpublic virtual async Task Get{methodName}{(throws ? "_throws" : "")}_for_{magnitude.ToLowerInvariant()}_{dbType}_with_GetFieldValueAsync()");
if (expected == "Overflow")
writer.WriteLine($" => await TestExceptionAsync(DbType.{dbType}, ValueKind.{magnitude}, async x => await x.GetFieldValueAsync<{typeName}>(0), typeof(OverflowException));");
else if (expected == "Null")
writer.WriteLine($" => await TestExceptionAsync(DbType.{dbType}, ValueKind.{magnitude}, async x => await x.GetFieldValueAsync<{typeName}>(0), Fixture.NullValueExceptionType);");
else if (expected == "InvalidCast")
writer.WriteLine($" => await TestExceptionAsync(DbType.{dbType}, ValueKind.{magnitude}, async x => await x.GetFieldValueAsync<{typeName}>(0), typeof(InvalidCastException));");
else
writer.WriteLine($" => await TestGetValueAsync(DbType.{dbType}, ValueKind.{magnitude}, async x => await x.GetFieldValueAsync<{typeName}>(0), {expected});");
}
}
}
foreach (var type in s_fieldTypes)
{
writer.WriteLine();
writer.WriteLine("\t\t[SkippableFact]");
writer.WriteLine($"\t\tpublic virtual void GetFieldType_for_{type.DbType}() => TestGetFieldType(DbType.{type.DbType}, ValueKind.One, typeof({type.Type}));");
}
foreach (var type in s_fieldTypes)
{
writer.WriteLine();
writer.WriteLine("\t\t[SkippableFact]");
writer.WriteLine($"\t\tpublic virtual void GetFieldValue_for_{type.DbType}() => TestGetFieldValue(DbType.{type.DbType}, ValueKind.One, {type.Value});");
}
writer.WriteLine();
writer.WriteLine("\t\t[SkippableFact]");
writer.WriteLine($"\t\tpublic virtual void GetFieldValue_for_null() => TestGetFieldValue(DbType.String, ValueKind.Null, DBNull.Value);");
foreach (var type in s_fieldTypes)
{
writer.WriteLine();
writer.WriteLine("\t\t[SkippableFact]");
writer.WriteLine($"\t\tpublic virtual void GetValue_for_{type.DbType}() => TestGetValue(DbType.{type.DbType}, ValueKind.One, {type.Value});");
}
writer.WriteLine();
writer.WriteLine("\t\t[SkippableFact]");
writer.WriteLine($"\t\tpublic virtual void GetValue_for_null() => TestGetValue(DbType.String, ValueKind.Null, DBNull.Value);");
writer.WriteLine("\t}");
writer.WriteLine("}");
}
}
// DbType/Kind/GetX
static readonly Dictionary<string, string> s_expected = new Dictionary<string, string>
{
{ "Boolean/Empty/*", "Ignore" },
{ "Byte/Empty/*", "Ignore" },
{ "Currency/Empty/*", "Ignore" },
{ "Date/Empty/*", "Ignore" },
{ "DateTime/Empty/*", "Ignore" },
{ "DateTimeOffset/Empty/*", "Ignore" },
{ "Decimal/Empty/*", "Ignore" },
{ "Double/Empty/*", "Ignore" },
{ "Guid/Empty/*", "Ignore" },
{ "Int16/Empty/*", "Ignore" },
{ "Int32/Empty/*", "Ignore" },
{ "Int64/Empty/*", "Ignore" },
{ "SByte/Empty/*", "Ignore" },
{ "Single/Empty/*", "Ignore" },
{ "Time/Empty/*", "Ignore" },
{ "UInt16/Empty/*", "Ignore" },
{ "UInt32/Empty/*", "Ignore" },
{ "UInt64/Empty/*", "Ignore" },
{ "Binary/Minimum/*", "Ignore" },
{ "Binary/Maximum/*", "Ignore" },
{ "Guid/Minimum/*", "Ignore" },
{ "Guid/Maximum/*", "Ignore" },
{ "String/Minimum/*", "Ignore" },
{ "String/Maximum/*", "Ignore" },
{ "Binary/Null/Bytes", "Null" },
{ "Binary/Null/*", "Ignore" },
{ "Boolean/Null/Boolean", "Null" },
{ "Boolean/Null/*", "Ignore" },
{ "Byte/Null/Byte", "Null" },
{ "Byte/Null/*", "Ignore" },
{ "Currency/Null/*", "Null" },
{ "Date/Null/DateTime", "Null" },
{ "Date/Null/*", "Ignore" },
{ "DateTime/Null/DateTime", "Null" },
{ "DateTime/Null/*", "Ignore" },
{ "DateTimeOffset/Null/*", "Ignore" },
{ "Decimal/Null/Decimal", "Null" },
{ "Decimal/Null/*", "Ignore" },
{ "Double/Null/Double", "Null" },
{ "Double/Null/*", "Ignore" },
{ "Guid/Null/Guid", "Null" },
{ "Guid/Null/*", "Ignore" },
{ "Int16/Null/Int16", "Null" },
{ "Int16/Null/*", "Ignore" },
{ "Int32/Null/Int32", "Null" },
{ "Int32/Null/*", "Ignore" },
{ "Int64/Null/Int64", "Null" },
{ "Int64/Null/*", "Ignore" },
{ "SByte/Null/*", "Ignore" },
{ "Single/Null/Float", "Null" },
{ "Single/Null/*", "Ignore" },
{ "String/Null/String", "Null" },
{ "String/Null/*", "Ignore" },
{ "Time/Null/*", "Ignore" },
{ "UInt16/Null/*", "Ignore" },
{ "UInt32/Null/*", "Ignore" },
{ "UInt64/Null/*", "Ignore" },
{ "Date/Zero/*", "Ignore" },
{ "DateTime/Zero/*", "Ignore" },
{ "DateTimeOffset/Zero/*", "Ignore" },
{ "Binary/*/Boolean", "InvalidCast" },
{ "Date/*/Boolean", "InvalidCast" },
{ "DateTime/*/Boolean", "InvalidCast" },
{ "DateTimeOffset/*/Boolean", "InvalidCast" },
{ "Binary/Empty/Binary", "new byte[0]" },
{ "Binary/Zero/Binary", "new byte[1] { 0 }" },
{ "Binary/One/Binary", "new byte[1] { 1 }" },
{ "Binary/*/Byte", "InvalidCast" },
{ "Binary/*/Char", "InvalidCast" },
{ "Boolean/*/Byte", "InvalidCast" },
{ "Boolean/*/Char", "InvalidCast" },
{ "Boolean/*/Date", "InvalidCast" },
{ "Boolean/*/DateTime", "InvalidCast" },
{ "Boolean/*/DateTimeOffset", "InvalidCast" },
{ "Boolean/*/Decimal", "InvalidCast" },
{ "Boolean/*/Double", "InvalidCast" },
{ "Boolean/*/Float", "InvalidCast" },
{ "Boolean/*/Guid", "InvalidCast" },
{ "Boolean/*/Int16", "InvalidCast" },
{ "Boolean/*/Int32", "InvalidCast" },
{ "Boolean/*/Int64", "InvalidCast" },
{ "Boolean/*/String", "InvalidCast" },
{ "Boolean/*/Time", "InvalidCast" },
{ "Boolean/Zero/Boolean", "false" },
{ "Boolean/One/Boolean", "true" },
{ "Boolean/Minimum/Boolean", "false" },
{ "Boolean/Maximum/Boolean", "true" },
{ "Byte/*/Binary", "InvalidCast" },
{ "Byte/*/Boolean", "InvalidCast" },
{ "Byte/*/Char", "InvalidCast" },
{ "Byte/*/String", "InvalidCast" },
{ "Byte/Zero/Byte", "(byte) 0" },
{ "Byte/One/Byte", "(byte) 1" },
{ "Byte/Minimum/Byte", "(byte) 0" },
{ "Byte/Maximum/Byte", "(byte) 255" },
{ "Byte/*/Date", "InvalidCast" },
{ "Byte/*/DateTime", "InvalidCast" },
{ "Byte/*/DateTimeOffset", "InvalidCast" },
{ "Byte/*/Guid", "InvalidCast" },
{ "Byte/*/Time", "InvalidCast" },
{ "Currency/*/Boolean", "InvalidCast" },
{ "Currency/*/Byte", "InvalidCast" },
{ "Currency/*/Char", "InvalidCast" },
{ "Currency/*/String", "InvalidCast" },
{ "Currency/Zero/Decimal", "0m" },
{ "Currency/One/Decimal", "1m" },
{ "Currency/Minimum/Decimal", "-922337203685477.5808m" },
{ "Currency/Maximum/Decimal", "922337203685477.5807m" },
{ "Date/*/Byte", "InvalidCast" },
{ "Date/*/Char", "InvalidCast" },
{ "Date/One/DateTime", "new DateTime(1111, 11, 11)" },
{ "Date/Minimum/DateTime", "new DateTime(1, 1, 1)" },
{ "Date/Maximum/DateTime", "new DateTime(9999, 12, 31)" },
{ "Date/*/Guid", "InvalidCast" },
{ "DateTime/*/Byte", "InvalidCast" },
{ "DateTime/*/Char", "InvalidCast" },
{ "DateTime/One/DateTime", "new DateTime(1111, 11, 11, 11, 11, 11, 111)" },
{ "DateTime/Minimum/DateTime", "new DateTime(1, 1, 1)" },
{ "DateTime/Maximum/DateTime", "new DateTime(9999, 12, 31, 23, 59, 59, 999)" },
{ "DateTime/*/Guid", "InvalidCast" },
{ "DateTimeOffset/*/Byte", "InvalidCast" },
{ "DateTimeOffset/*/Char", "InvalidCast" },
/*{ "DateTimeOffset/One/DateTimeOffset", "new DateTimeOffset(1111, 11, 11, 11, 11, 11, 111, new TimeSpan(11, 11))" },
{ "DateTimeOffset/Minimum/DateTimeOffset", "new DateTime(1, 1, 1)" },
{ "DateTimeOffset/Maximum/DateTimeOffset", "new DateTime(9999, 12, 31, 23, 59, 59, 999, new TimeSpan(14, 00))" },*/
{ "DateTimeOffset/*/Guid", "InvalidCast" },
{ "Decimal/*/Binary", "InvalidCast" },
{ "Decimal/*/Boolean", "InvalidCast" },
{ "Decimal/*/Byte", "InvalidCast" },
{ "Decimal/*/Char", "InvalidCast" },
{ "Decimal/*/Date", "InvalidCast" },
{ "Decimal/*/DateTime", "InvalidCast" },
{ "Decimal/*/DateTimeOffset", "InvalidCast" },
{ "Decimal/*/String", "InvalidCast" },
{ "Decimal/Zero/Decimal", "0m" },
{ "Decimal/One/Decimal", "1m" },
{ "Decimal/Minimum/Decimal", "0.000000000000001m" },
{ "Decimal/Maximum/Decimal", "99999999999999999999.999999999999999m" },
{ "Decimal/Zero/Float", "0f" },
{ "Decimal/One/Float", "1f" },
{ "Decimal/Minimum/Float", "0.000000000000001f" },
{ "Decimal/Maximum/Float", "1e20f" },
{ "Decimal/Zero/Double", "0.0" },
{ "Decimal/One/Double", "1.0" },
{ "Decimal/Minimum/Double", "0.000000000000001" },
{ "Decimal/Maximum/Double", "1e20" },
{ "Decimal/*/Guid", "InvalidCast" },
{ "Decimal/*/Time", "InvalidCast" },
{ "Double/*/Binary", "InvalidCast" },
{ "Double/*/Boolean", "InvalidCast" },
{ "Double/*/Byte", "InvalidCast" },
{ "Double/*/Char", "InvalidCast" },
{ "Double/*/Date", "InvalidCast" },
{ "Double/*/DateTime", "InvalidCast" },
{ "Double/*/DateTimeOffset", "InvalidCast" },
{ "Double/*/Guid", "InvalidCast" },
{ "Double/*/String", "InvalidCast" },
{ "Double/*/Decimal", "InvalidCast" },
{ "Double/Zero/Double", "0.0" },
{ "Double/One/Double", "1.0" },
{ "Double/Minimum/Double", "2.23E-308" },
{ "Double/Maximum/Double", "1.79e308" },
{ "Double/*/Float", "InvalidCast" },
{ "Double/*/Time", "InvalidCast" },
{ "Guid/*/Boolean", "InvalidCast" },
{ "Guid/*/Byte", "InvalidCast" },
{ "Guid/*/Char", "InvalidCast" },
{ "Guid/*/String", "InvalidCast" },
{ "Guid/Zero/Guid", "new Guid()" },
{ "Guid/One/Guid", "new Guid(\"11111111-1111-1111-1111-111111111111\")" },
{ "Guid/Minimum/Guid", "new Guid(\"33221100-5544-7766-9988-aabbccddeeff\")" },
{ "Guid/Maximum/Guid", "new Guid(\"ccddeeff-aabb-8899-7766-554433221100\")" },
{ "Int16/*/Binary", "InvalidCast" },
{ "Int16/*/Boolean", "InvalidCast" },
{ "Int16/*/Byte", "InvalidCast" },
{ "Int16/*/Char", "InvalidCast" },
{ "Int16/*/Date", "InvalidCast" },
{ "Int16/*/DateTime", "InvalidCast" },
{ "Int16/*/DateTimeOffset", "InvalidCast" },
{ "Int16/*/Guid", "InvalidCast" },
{ "Int16/*/String", "InvalidCast" },
{ "Int16/Zero/Int16", "(short) 0" },
{ "Int16/One/Int16", "(short) 1" },
{ "Int16/Minimum/Int16", "(short) -32768" },
{ "Int16/Maximum/Int16", "(short) 32767" },
{ "Int16/*/Time", "InvalidCast" },
{ "Int16/Zero/Int32", "0" },
{ "Int16/One/Int32", "1" },
{ "Int16/Minimum/Int32", "-32768" },
{ "Int16/Maximum/Int32", "32767" },
{ "Int16/Zero/Int64", "0L" },
{ "Int16/One/Int64", "1L" },
{ "Int16/Minimum/Int64", "-32768L" },
{ "Int16/Maximum/Int64", "32767L" },
{ "Int32/*/Binary", "InvalidCast" },
{ "Int32/*/Boolean", "InvalidCast" },
{ "Int32/*/Byte", "InvalidCast" },
{ "Int32/*/Char", "InvalidCast" },
{ "Int32/*/Date", "InvalidCast" },
{ "Int32/*/DateTime", "InvalidCast" },
{ "Int32/*/DateTimeOffset", "InvalidCast" },
{ "Int32/*/Guid", "InvalidCast" },
{ "Int32/*/String", "InvalidCast" },
{ "Int32/Zero/Int16", "(short) 0" },
{ "Int32/One/Int16", "(short) 1" },
{ "Int32/Minimum/Int16", "Overflow" },
{ "Int32/Maximum/Int16", "Overflow" },
{ "Int32/Zero/Int32", "0" },
{ "Int32/One/Int32", "1" },
{ "Int32/Minimum/Int32", "-2147483648" },
{ "Int32/Maximum/Int32", "2147483647" },
{ "Int32/Zero/Int64", "0L" },
{ "Int32/One/Int64", "1L" },
{ "Int32/Minimum/Int64", "-2147483648L" },
{ "Int32/Maximum/Int64", "2147483647L" },
{ "Int32/*/Time", "InvalidCast" },
{ "Int64/*/Binary", "InvalidCast" },
{ "Int64/*/Boolean", "InvalidCast" },
{ "Int64/*/Byte", "InvalidCast" },
{ "Int64/*/Char", "InvalidCast" },
{ "Int64/*/Date", "InvalidCast" },
{ "Int64/*/DateTime", "InvalidCast" },
{ "Int64/*/DateTimeOffset", "InvalidCast" },
{ "Int64/*/Guid", "InvalidCast" },
{ "Int64/*/String", "InvalidCast" },
{ "Int64/Zero/Int16", "(short) 0" },
{ "Int64/One/Int16", "(short) 1" },
{ "Int64/Minimum/Int16", "Overflow" },
{ "Int64/Maximum/Int16", "Overflow" },
{ "Int64/Zero/Int32", "0" },
{ "Int64/One/Int32", "1" },
{ "Int64/Minimum/Int32", "Overflow" },
{ "Int64/Maximum/Int32", "Overflow" },
{ "Int64/Zero/Int64", "0L" },
{ "Int64/One/Int64", "1L" },
{ "Int64/Minimum/Int64", "-9223372036854775808L" },
{ "Int64/Maximum/Int64", "9223372036854775807L" },
{ "Int64/*/Time", "InvalidCast" },
{ "SByte/*/Boolean", "InvalidCast" },
{ "SByte/*/Byte", "InvalidCast" },
{ "SByte/*/Char", "InvalidCast" },
{ "SByte/*/String", "InvalidCast" },
{ "Single/*/Binary", "InvalidCast" },
{ "Single/*/Boolean", "InvalidCast" },
{ "Single/*/Byte", "InvalidCast" },
{ "Single/*/Char", "InvalidCast" },
{ "Single/*/Date", "InvalidCast" },
{ "Single/*/DateTime", "InvalidCast" },
{ "Single/*/DateTimeOffset", "InvalidCast" },
{ "Single/*/Guid", "InvalidCast" },
{ "Single/*/String", "InvalidCast" },
{ "Single/*/Decimal", "InvalidCast" },
{ "Single/Zero/Double", "0.0" },
{ "Single/One/Double", "1.0" },
{ "Single/Minimum/Double", "1.1799999457746311E-38" },
{ "Single/Maximum/Double", "3.3999999521443642E+38" },
{ "Single/Zero/Float", "0f" },
{ "Single/One/Float", "1f" },
{ "Single/Minimum/Float", "1.18E-38f" },
{ "Single/Maximum/Float", "3.40e38f" },
{ "Single/*/Time", "InvalidCast" },
{ "String/*/Boolean", "InvalidCast" },
{ "String/*/Byte", "InvalidCast" },
{ "String/*/Decimal", "InvalidCast" },
{ "String/*/Double", "InvalidCast" },
{ "String/*/Float", "InvalidCast" },
{ "String/*/Int16", "InvalidCast" },
{ "String/*/Int32", "InvalidCast" },
{ "String/*/Int64", "InvalidCast" },
{ "String/*/SByte", "InvalidCast" },
{ "String/Empty/Char", "InvalidCast" },
{ "String/Empty/String", "\"\"" },
{ "String/Zero/Char", "'0'" },
{ "String/Zero/String", "\"0\"" },
{ "String/One/Char", "'1'" },
{ "String/One/String", "\"1\"" },
{ "Time/*/Boolean", "InvalidCast" },
{ "Time/*/Byte", "InvalidCast" },
{ "Time/*/Char", "InvalidCast" },
{ "Time/Zero/DateTime", "InvalidCast" },
{ "Time/One/DateTime", "InvalidCast" },
{ "Time/Minimum/DateTime", "InvalidCast" },
{ "Time/Maximum/DateTime", "InvalidCast" },
{ "Time/*/Guid", "InvalidCast" },
{ "UInt16/*/Boolean", "InvalidCast" },
{ "UInt16/*/Byte", "InvalidCast" },
{ "UInt16/*/Char", "InvalidCast" },
{ "UInt16/*/String", "InvalidCast" },
{ "UInt16/Zero/Int16", "(short) 0" },
{ "UInt16/One/Int16", "(short) 1" },
{ "UInt16/Minimum/Int16", "(short) 0" },
{ "UInt16/Maximum/Int16", "Overflow" },
{ "UInt16/Zero/Int32", "0" },
{ "UInt16/One/Int32", "1" },
{ "UInt16/Minimum/Int32", "0" },
{ "UInt16/Maximum/Int32", "65535" },
{ "UInt16/Zero/Int64", "0L" },
{ "UInt16/One/Int64", "1L" },
{ "UInt16/Minimum/Int64", "0L" },
{ "UInt16/Maximum/Int64", "65535L" },
{ "UInt32/*/Boolean", "InvalidCast" },
{ "UInt32/*/Byte", "InvalidCast" },
{ "UInt32/*/Char", "InvalidCast" },
{ "UInt32/*/String", "InvalidCast" },
{ "UInt32/Zero/Int32", "0" },
{ "UInt32/One/Int32", "1" },
{ "UInt32/Minimum/Int32", "0" },
{ "UInt32/Maximum/Int32", "Overflow" },
{ "UInt64/*/Boolean", "InvalidCast" },
{ "UInt64/*/Byte", "InvalidCast" },
{ "UInt64/*/Char", "InvalidCast" },
{ "UInt64/*/String", "InvalidCast" },
{ "UInt64/Zero/Int64", "0L" },
{ "UInt64/One/Int64", "1L" },
{ "UInt64/Minimum/Int64", "0L" },
{ "UInt64/Maximum/Int64", "Overflow" },
};
static readonly DbType[] s_dbTypes = new[]
{
DbType.Binary,
DbType.Boolean,
DbType.Byte,
DbType.Currency,
DbType.Date,
DbType.DateTime,
DbType.DateTimeOffset,
DbType.Decimal,
DbType.Double,
DbType.Guid,
DbType.Int16,
DbType.Int32,
DbType.Int64,
DbType.SByte,
DbType.Single,
DbType.String,
DbType.Time,
DbType.UInt16,
DbType.UInt32,
DbType.UInt64,
};
static readonly string[] s_methods = new[]
{
"Boolean",
"Byte",
"Char",
"DateTime",
"Decimal",
"Double",
"Float",
"Guid",
"Int16",
"Int32",
"Int64",
"String",
};
static readonly Dictionary<string, string> s_methodToType = new Dictionary<string, string>
{
{ "Boolean", "bool" },
{ "Byte", "byte" },
{ "Char", "char" },
{ "DateTime", "DateTime" },
{ "Decimal", "decimal" },
{ "Double", "double" },
{ "Float", "float" },
{ "Guid", "Guid" },
{ "Int16", "short" },
{ "Int32", "int" },
{ "Int64", "long" },
{ "String", "string" },
};
static readonly IReadOnlyList<(DbType DbType, string Type, string Value)> s_fieldTypes = new List<(DbType, string, string)>()
{
{ (DbType.Binary, "byte[]", "new byte[] { 0x11 }") },
{ (DbType.Boolean, "bool", "true") },
{ (DbType.Byte, "byte", "(byte) 1") },
{ (DbType.Currency, "decimal", "1m") },
{ (DbType.Date, "DateTime", "new DateTime(1111, 11, 11)") },
{ (DbType.DateTime, "DateTime", "new DateTime(1111, 11, 11, 11, 11, 11, 111)") },
{ (DbType.DateTimeOffset, "DateTimeOffset", "new DateTimeOffset(1111, 11, 11, 11, 11, 11, 111, new TimeSpan(11, 11, 0))") },
{ (DbType.Decimal, "decimal", "1m") },
{ (DbType.Double, "double", "1.0") },
{ (DbType.Guid, "Guid", "new Guid(\"11111111111111111111111111111111\")") },
{ (DbType.Int16, "short", "(short) 1") },
{ (DbType.Int32, "int", "1") },
{ (DbType.Int64, "long", "1L") },
{ (DbType.SByte, "sbyte", "(sbyte) 1") },
{ (DbType.Single, "float", "1f") },
{ (DbType.String, "string", "\"1\"") },
{ (DbType.Time, "TimeSpan", "new TimeSpan(0, 11, 11, 11, 111)") },
{ (DbType.UInt16, "ushort", "(ushort) 1") },
{ (DbType.UInt32, "uint", "1u") },
{ (DbType.UInt64, "ulong", "1ul") },
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment