-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSqlBuilderFactory.cs
106 lines (96 loc) · 4.25 KB
/
SqlBuilderFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using InterpolatedSql.Dapper.SqlBuilders;
using InterpolatedSql.SqlBuilders;
using System;
using System.Data;
using SqlBuilder = InterpolatedSql.Dapper.SqlBuilders.SqlBuilder;
namespace InterpolatedSql.Dapper
{
/// <summary>
/// Creates <see cref="ISqlBuilder"/>
/// </summary>
public class SqlBuilderFactory
{
/// <summary>
/// Creates a new IInterpolatedSqlBuilderBase of type B
/// </summary>
public virtual B Create<B>(IDbConnection connection)
where B : IDapperSqlBuilder
{
var ctor = typeof(B).GetConstructor(new Type[] { typeof(IDbConnection) });
B builder = (B)ctor.Invoke(new object[] { connection });
return builder;
}
/// <summary>
/// Creates a new IInterpolatedSqlBuilderBase of type B
/// </summary>
public virtual B Create<B>(IDbConnection connection, InterpolatedSqlBuilderOptions options)
where B : IDapperSqlBuilder
{
var ctor = typeof(B).GetConstructor(new Type[] { typeof(IDbConnection), typeof(InterpolatedSqlBuilderOptions) });
B builder = (B)ctor.Invoke(new object[] { connection, options });
return builder;
}
/// <summary>
/// Creates the default IInterpolatedSqlBuilder, which by default is SqlBuilder
/// </summary>
public virtual SqlBuilder Create(IDbConnection connection, InterpolatedSqlBuilderOptions? options = null)
{
SqlBuilder builder = new SqlBuilder(connection, options);
return builder;
}
/// <summary>
/// Creates a new IInterpolatedSqlBuilderBase of type B
/// </summary>
public virtual B Create<B>(IDbConnection connection, FormattableString command)
where B : IDapperSqlBuilder
{
var ctor = typeof(B).GetConstructor(new Type[] { typeof(IDbConnection), typeof(FormattableString) });
B builder = (B)ctor.Invoke(new object[] { connection, command });
return builder;
}
/// <summary>
/// Creates a new IInterpolatedSqlBuilderBase of type B
/// </summary>
public virtual B Create<B>(IDbConnection connection, FormattableString command, InterpolatedSqlBuilderOptions? options = null)
where B : IDapperSqlBuilder
{
var ctor = typeof(B).GetConstructor(new Type[] { typeof(IDbConnection), typeof(FormattableString), typeof(InterpolatedSqlBuilderOptions) });
B builder = (B)ctor.Invoke(new object[] { connection, command, options });
return builder;
}
#if NET6_0_OR_GREATER
/// <summary>
/// Creates a new IInterpolatedSqlBuilderBase of type B
/// </summary>
public virtual B Create<B>(IDbConnection connection, int literalLength, int formattedCount)
where B : IDapperSqlBuilder
{
var ctor = typeof(B).GetConstructor(new Type[] { typeof(IDbConnection), typeof(int), typeof(int) });
B builder = (B)ctor.Invoke(new object[] { connection, literalLength, formattedCount });
return builder;
}
/// <summary>
/// Creates a new IInterpolatedSqlBuilder of type B
/// </summary>
public virtual B Create<B>(IDbConnection connection, int literalLength, int formattedCount, InterpolatedSqlBuilderOptions? options = null)
where B : IDapperSqlBuilder
{
var ctor = typeof(B).GetConstructor(new Type[] { typeof(IDbConnection), typeof(int), typeof(int), typeof(InterpolatedSqlBuilderOptions) });
B builder = (B)ctor.Invoke(new object?[] { connection, literalLength, formattedCount, options });
return builder;
}
/// <summary>
/// Creates new SqlBuilder
/// </summary>
public virtual SqlBuilder Create(IDbConnection connection, int literalLength, int formattedCount, InterpolatedSqlBuilderOptions? options = null)
{
SqlBuilder builder = new SqlBuilder(connection, literalLength, formattedCount, options);
return builder;
}
#endif
/// <summary>
/// Default Factory
/// </summary>
public static SqlBuilderFactory Default = new SqlBuilderFactory();
}
}