Upd dbreader extension

pull/1/head
Ogoun 5 years ago
parent 96a52a3705
commit 9e96c150cb

@ -0,0 +1,28 @@
using System.Threading;
namespace TestApp
{
public class HybrydLock
{
private AutoResetEvent _lock = new AutoResetEvent(false);
private volatile int _counter = 0;
public void Enter()
{
if (Interlocked.Increment(ref _counter) == 1)
{
return;
}
_lock.WaitOne();
}
public void Leave()
{
if (Interlocked.Decrement(ref _counter) == 0)
{
return;
}
_lock.Set();
}
}
}

@ -33,7 +33,8 @@ namespace ZeroLevel.SqlServer
{
public static T Read<T>(this DbDataReader reader, int index)
{
if (reader[index] == DBNull.Value) return default(T);
if (reader == null) return default;
if (reader[index] == DBNull.Value) return default;
Type t;
if ((t = Nullable.GetUnderlyingType(typeof(T))) != null)
{
@ -43,7 +44,53 @@ namespace ZeroLevel.SqlServer
}
public static T Read<T>(this DbDataReader reader, string name)
{
if (reader[name] == DBNull.Value) return default(T);
if (reader == null) return default;
if (reader[name] == DBNull.Value) return default;
Type t;
if ((t = Nullable.GetUnderlyingType(typeof(T))) != null)
{
return (T)Convert.ChangeType(reader[name], t);
}
return (T)Convert.ChangeType(reader[name], typeof(T));
}
public static T Read<T>(this IDataReader reader, int index)
{
if (reader == null) return default;
if (reader[index] == DBNull.Value) return default;
Type t;
if ((t = Nullable.GetUnderlyingType(typeof(T))) != null)
{
return (T)Convert.ChangeType(reader[index], t);
}
return (T)Convert.ChangeType(reader[index], typeof(T));
}
public static T Read<T>(this IDataReader reader, string name)
{
if (reader == null) return default;
if (reader[name] == DBNull.Value) return default;
Type t;
if ((t = Nullable.GetUnderlyingType(typeof(T))) != null)
{
return (T)Convert.ChangeType(reader[name], t);
}
return (T)Convert.ChangeType(reader[name], typeof(T));
}
public static T Read<T>(this DataRow reader, int index)
{
if (reader == null) return default;
if (reader.ItemArray[index] == DBNull.Value) return default;
Type t;
if ((t = Nullable.GetUnderlyingType(typeof(T))) != null)
{
return (T)Convert.ChangeType(reader.ItemArray[index], t);
}
return (T)Convert.ChangeType(reader.ItemArray[index], typeof(T));
}
public static T Read<T>(this DataRow reader, string name)
{
if (reader == null) return default;
if (reader[name] == DBNull.Value) return default;
Type t;
if ((t = Nullable.GetUnderlyingType(typeof(T))) != null)
{

Loading…
Cancel
Save

Powered by TurnKey Linux.