Format better

This commit is contained in:
Edgar Luque 2017-12-09 16:04:27 +01:00
parent d3fadaf264
commit 83f02e49aa

View file

@ -106,7 +106,7 @@ namespace TShockAPI.DB
public static IDbConnection CloneEx(this IDbConnection conn) public static IDbConnection CloneEx(this IDbConnection conn)
{ {
var clone = (IDbConnection) Activator.CreateInstance(conn.GetType()); var clone = (IDbConnection)Activator.CreateInstance(conn.GetType());
clone.ConnectionString = conn.ConnectionString; clone.ConnectionString = conn.ConnectionString;
return clone; return clone;
} }
@ -123,84 +123,84 @@ namespace TShockAPI.DB
private static readonly Dictionary<Type, Func<IDataReader, int, object>> ReadFuncs = new Dictionary private static readonly Dictionary<Type, Func<IDataReader, int, object>> ReadFuncs = new Dictionary
<Type, Func<IDataReader, int, object>> <Type, Func<IDataReader, int, object>>
{ {
{ {
typeof (bool), typeof (bool),
(s, i) => s.GetBoolean(i) (s, i) => s.GetBoolean(i)
}, },
{ {
typeof (bool?), typeof (bool?),
(s, i) => s.IsDBNull(i) ? null : (object)s.GetBoolean(i) (s, i) => s.IsDBNull(i) ? null : (object)s.GetBoolean(i)
}, },
{ {
typeof (byte), typeof (byte),
(s, i) => s.GetByte(i) (s, i) => s.GetByte(i)
}, },
{ {
typeof (byte?), typeof (byte?),
(s, i) => s.IsDBNull(i) ? null : (object)s.GetByte(i) (s, i) => s.IsDBNull(i) ? null : (object)s.GetByte(i)
}, },
{ {
typeof (Int16), typeof (Int16),
(s, i) => s.GetInt16(i) (s, i) => s.GetInt16(i)
}, },
{ {
typeof (Int16?), typeof (Int16?),
(s, i) => s.IsDBNull(i) ? null : (object)s.GetInt16(i) (s, i) => s.IsDBNull(i) ? null : (object)s.GetInt16(i)
}, },
{ {
typeof (Int32), typeof (Int32),
(s, i) => s.GetInt32(i) (s, i) => s.GetInt32(i)
}, },
{ {
typeof (Int32?), typeof (Int32?),
(s, i) => s.IsDBNull(i) ? null : (object)s.GetInt32(i) (s, i) => s.IsDBNull(i) ? null : (object)s.GetInt32(i)
}, },
{ {
typeof (Int64), typeof (Int64),
(s, i) => s.GetInt64(i) (s, i) => s.GetInt64(i)
}, },
{ {
typeof (Int64?), typeof (Int64?),
(s, i) => s.IsDBNull(i) ? null : (object)s.GetInt64(i) (s, i) => s.IsDBNull(i) ? null : (object)s.GetInt64(i)
}, },
{ {
typeof (string), typeof (string),
(s, i) => s.GetString(i) (s, i) => s.GetString(i)
}, },
{ {
typeof (decimal), typeof (decimal),
(s, i) => s.GetDecimal(i) (s, i) => s.GetDecimal(i)
}, },
{ {
typeof (decimal?), typeof (decimal?),
(s, i) => s.IsDBNull(i) ? null : (object)s.GetDecimal(i) (s, i) => s.IsDBNull(i) ? null : (object)s.GetDecimal(i)
}, },
{ {
typeof (float), typeof (float),
(s, i) => s.GetFloat(i) (s, i) => s.GetFloat(i)
}, },
{ {
typeof (float?), typeof (float?),
(s, i) => s.IsDBNull(i) ? null : (object)s.GetFloat(i) (s, i) => s.IsDBNull(i) ? null : (object)s.GetFloat(i)
}, },
{ {
typeof (double), typeof (double),
(s, i) => s.GetDouble(i) (s, i) => s.GetDouble(i)
}, },
{ {
typeof (double?), typeof (double?),
(s, i) => s.IsDBNull(i) ? null : (object)s.GetDouble(i) (s, i) => s.IsDBNull(i) ? null : (object)s.GetDouble(i)
}, },
{ {
typeof (DateTime), typeof (DateTime),
(s, i) => s.IsDBNull(i) ? null : (object)s.GetDateTime(i) (s, i) => s.IsDBNull(i) ? null : (object)s.GetDateTime(i)
}, },
{ {
typeof (object), typeof (object),
(s, i) => s.GetValue(i) (s, i) => s.GetValue(i)
}, },
}; };
public static T Get<T>(this IDataReader reader, string column) public static T Get<T>(this IDataReader reader, string column)
{ {
@ -212,8 +212,8 @@ namespace TShockAPI.DB
if (reader.IsDBNull(column)) if (reader.IsDBNull(column))
return default(T); return default(T);
if (ReadFuncs.ContainsKey(typeof (T))) if (ReadFuncs.ContainsKey(typeof(T)))
return (T) ReadFuncs[typeof (T)](reader, column); return (T)ReadFuncs[typeof(T)](reader, column);
throw new NotImplementedException(); throw new NotImplementedException();
} }