Skip to content

Commit dc8d8e0

Browse files
committed
Removed new() constraint for P
1 parent 642be6b commit dc8d8e0

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

DirectSQL/Database.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public delegate void ReadSqlResult<R,CMD,T,C,P>(SqlResult<R,CMD,T,C,P> result)
6060
where R : IDataReader
6161
where T : IDbTransaction
6262
where C : IDbConnection
63-
where P : IDataParameter,
64-
new();
63+
where P : IDataParameter;
6564

6665
/// <summary>
6766
/// Database class is entry point of DirectSQL library.
@@ -76,8 +75,7 @@ public abstract class Database<C,T,CMD,R,P>
7675
where T : IDbTransaction
7776
where CMD : IDbCommand
7877
where R : IDataReader
79-
where P : IDataParameter,
80-
new()
78+
where P : IDataParameter
8179
{
8280
/// <summary>
8381
/// Asynchronous process with a connection
@@ -781,12 +779,20 @@ private static (String sql, (String,Object)[] parameters) ExtractSqlAndParam(For
781779

782780
public static P CreateParameter(string name, object value)
783781
{
784-
return new P() { ParameterName = name, Value = value };
782+
var paramType = typeof(P);
783+
var constructor = paramType.GetConstructor(new Type[0]);
784+
P param = (P) constructor.Invoke(new object[0]);
785+
param.ParameterName = name;
786+
param.Value = value;
787+
788+
return param;
785789
}
786790

787791
public static P CreateParameter(string name, object value, DbType type)
788792
{
789-
return new P() { ParameterName = name, Value = value, DbType = type };
793+
var param = CreateParameter(name,value);
794+
param.DbType = type;
795+
return param;
790796
}
791797

792798
public static P[] ConvertToDbParameter((String name,Object value)[] tuples)

DirectSQL/SqlResult.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public class SqlResult<R,CMD,T,C,P>:EnumerableObject<dynamic>,IDisposable
2222
where CMD : IDbCommand
2323
where T : IDbTransaction
2424
where C : IDbConnection
25-
where P : IDataParameter,
26-
new()
25+
where P : IDataParameter
2726
{
2827
private R _reader;
2928
private CMD _command;

0 commit comments

Comments
 (0)