diff --git a/Dysnomia.Common.SQL/DbReaderMapper.cs b/Dysnomia.Common.SQL/DbReaderMapper.cs index 29aba06..0b64011 100644 --- a/Dysnomia.Common.SQL/DbReaderMapper.cs +++ b/Dysnomia.Common.SQL/DbReaderMapper.cs @@ -29,7 +29,7 @@ public static class DbReaderMapper { /** * String from reader */ - public static string GetString(IDataReader reader, string key, bool catchNull = true, string defaultValue = "") { + public static string GetString(this IDataReader reader, string key, bool catchNull = true, string defaultValue = "") { var id = reader.GetOrdinal(key); if(!catchNull || !reader.IsDBNull(id)) { @@ -42,7 +42,7 @@ public static string GetString(IDataReader reader, string key, bool catchNull = /** * Short/Int16 from reader */ - public static short GetInt16(IDataReader reader, string key, bool catchNull = true, short defaultValue = 0) { + public static short GetInt16(this IDataReader reader, string key, bool catchNull = true, short defaultValue = 0) { var id = reader.GetOrdinal(key); if(!catchNull || !reader.IsDBNull(id)) { @@ -51,14 +51,14 @@ public static short GetInt16(IDataReader reader, string key, bool catchNull = tr return defaultValue; } - public static short GetShort(IDataReader reader, string key, bool catchNull = true, short defaultValue = 0) { + public static short GetShort(this IDataReader reader, string key, bool catchNull = true, short defaultValue = 0) { return GetInt16(reader, key, catchNull, defaultValue); } /** * Nullable Short/Int16 from reader */ - public static short? GetNullableInt16(IDataReader reader, string key) { + public static short? GetNullableInt16(this IDataReader reader, string key) { var id = reader.GetOrdinal(key); if(!reader.IsDBNull(id)) { @@ -67,14 +67,14 @@ public static short GetShort(IDataReader reader, string key, bool catchNull = tr return null; } - public static short? GetNullableShort(IDataReader reader, string key) { + public static short? GetNullableShort(this IDataReader reader, string key) { return GetShort(reader, key); } /** * Int/Int32 from reader */ - public static int GetInt32(IDataReader reader, string key, bool catchNull = true, int defaultValue = 0) { + public static int GetInt32(this IDataReader reader, string key, bool catchNull = true, int defaultValue = 0) { var id = reader.GetOrdinal(key); if(!catchNull || !reader.IsDBNull(id)) { @@ -83,14 +83,14 @@ public static int GetInt32(IDataReader reader, string key, bool catchNull = true return defaultValue; } - public static int GetInt(IDataReader reader, string key, bool catchNull = true, short defaultValue = 0) { + public static int GetInt(this IDataReader reader, string key, bool catchNull = true, short defaultValue = 0) { return GetInt32(reader, key, catchNull, defaultValue); } /** * Nullable Int/Int32 from reader */ - public static int? GetNullableInt32(IDataReader reader, string key) { + public static int? GetNullableInt32(this IDataReader reader, string key) { var id = reader.GetOrdinal(key); if(!reader.IsDBNull(id)) { @@ -99,14 +99,14 @@ public static int GetInt(IDataReader reader, string key, bool catchNull = true, return null; } - public static int? GetNullableInt(IDataReader reader, string key) { + public static int? GetNullableInt(this IDataReader reader, string key) { return GetNullableInt32(reader, key); } /** * Int/Int32 from reader */ - public static long GetInt64(IDataReader reader, string key, bool catchNull = true, long defaultValue = 0) { + public static long GetInt64(this IDataReader reader, string key, bool catchNull = true, long defaultValue = 0) { var id = reader.GetOrdinal(key); if(!catchNull || !reader.IsDBNull(id)) { @@ -115,14 +115,14 @@ public static long GetInt64(IDataReader reader, string key, bool catchNull = tru return defaultValue; } - public static long GetLong(IDataReader reader, string key, bool catchNull = true, long defaultValue = 0) { + public static long GetLong(this IDataReader reader, string key, bool catchNull = true, long defaultValue = 0) { return GetInt64(reader, key, catchNull, defaultValue); } /** * Nullable Int/Int32 from reader */ - public static long? GetNullableInt64(IDataReader reader, string key) { + public static long? GetNullableInt64(this IDataReader reader, string key) { var id = reader.GetOrdinal(key); if(!reader.IsDBNull(id)) { @@ -131,14 +131,14 @@ public static long GetLong(IDataReader reader, string key, bool catchNull = true return null; } - public static long? GetNullableLong(IDataReader reader, string key) { + public static long? GetNullableLong(this IDataReader reader, string key) { return GetNullableInt64(reader, key); } /** * Decimal from reader */ - public static decimal GetDecimal(IDataReader reader, string key, bool catchNull = true, decimal defaultValue = 0) { + public static decimal GetDecimal(this IDataReader reader, string key, bool catchNull = true, decimal defaultValue = 0) { var id = reader.GetOrdinal(key); if(!catchNull || !reader.IsDBNull(id)) { @@ -151,7 +151,7 @@ public static decimal GetDecimal(IDataReader reader, string key, bool catchNull /** * Nullable Decimal from reader */ - public static decimal? GetNullableDecimal(IDataReader reader, string key) { + public static decimal? GetNullableDecimal(this IDataReader reader, string key) { var id = reader.GetOrdinal(key); if(!reader.IsDBNull(id)) { @@ -164,7 +164,7 @@ public static decimal GetDecimal(IDataReader reader, string key, bool catchNull /** * Boolean from reader */ - public static bool GetBoolean(IDataReader reader, string key, bool catchNull = true, bool defaultValue = false) { + public static bool GetBoolean(this IDataReader reader, string key, bool catchNull = true, bool defaultValue = false) { var id = reader.GetOrdinal(key); if(!catchNull || !reader.IsDBNull(id)) { @@ -177,7 +177,7 @@ public static bool GetBoolean(IDataReader reader, string key, bool catchNull = t /** * DateTime from reader */ - public static DateTime GetDateTime(IDataReader reader, string key, bool catchNull = true, DateTime defaultValue = new DateTime()) { + public static DateTime GetDateTime(this IDataReader reader, string key, bool catchNull = true, DateTime defaultValue = new DateTime()) { var id = reader.GetOrdinal(key); if(!catchNull || !reader.IsDBNull(id)) { @@ -190,7 +190,7 @@ public static bool GetBoolean(IDataReader reader, string key, bool catchNull = t /** * Nullable DateTime from reader */ - public static DateTime? GetNullableDateTime(IDataReader reader, string key) { + public static DateTime? GetNullableDateTime(this IDataReader reader, string key) { var id = reader.GetOrdinal(key); if(!reader.IsDBNull(id)) { @@ -203,7 +203,7 @@ public static bool GetBoolean(IDataReader reader, string key, bool catchNull = t /** * Guid */ - public static Guid GetGuid(IDataReader reader, string key, bool catchNull, Guid defaultValue) { + public static Guid GetGuid(this IDataReader reader, string key, bool catchNull, Guid defaultValue) { var id = reader.GetOrdinal(key); if(!catchNull || !reader.IsDBNull(id)) { @@ -212,10 +212,10 @@ public static Guid GetGuid(IDataReader reader, string key, bool catchNull, Guid return defaultValue; } - public static Guid GetGuid(IDataReader reader, string key, bool catchNull, string guidData) { + public static Guid GetGuid(this IDataReader reader, string key, bool catchNull, string guidData) { return GetGuid(reader, key, catchNull, Guid.Parse(guidData)); } - public static Guid GetGuid(IDataReader reader, string key, bool catchNull = true) { + public static Guid GetGuid(this IDataReader reader, string key, bool catchNull = true) { return GetGuid(reader, key, catchNull, Guid.Empty); } } diff --git a/Dysnomia.Common.SQL/Dysnomia.Common.SQL.csproj b/Dysnomia.Common.SQL/Dysnomia.Common.SQL.csproj index 6c77f6d..fc56d44 100644 --- a/Dysnomia.Common.SQL/Dysnomia.Common.SQL.csproj +++ b/Dysnomia.Common.SQL/Dysnomia.Common.SQL.csproj @@ -9,10 +9,10 @@ https://github.com/Dysnomia-Studio/Dysnomia.Common.SQL https://github.com/Dysnomia-Studio/Dysnomia.Common.SQL Github - Added DbReaderMapper.GetDecimal() - 1.0.4 - 1.0.4.0 - 1.0.4.0 + Using extension methods instead of parameters + 1.1.0-rc1 + 1.1.0.0 + 1.1.0.0