@@ -180,6 +180,15 @@ public TThis UseCancellationToken(CancellationToken token)
180
180
181
181
#region AddParam
182
182
183
+ /// <summary>
184
+ /// Shortcut to add a parameter to the params list.
185
+ /// </summary>
186
+ protected TThis AddParam ( Param param )
187
+ {
188
+ Params . Add ( param ) ;
189
+ return ( TThis ) this ;
190
+ }
191
+
183
192
/// <summary>
184
193
/// Adds a parameter to the params list.
185
194
/// </summary>
@@ -191,103 +200,39 @@ public TThis UseCancellationToken(CancellationToken token)
191
200
/// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception>
192
201
/// <exception cref="ArgumentException"><paramref name="name"/> is blank.</exception>
193
202
public TThis AddParam ( string name , object value , TDbType type , ParameterDirection direction = ParameterDirection . Input )
194
- {
195
- if ( name is null ) throw new ArgumentNullException ( nameof ( name ) ) ;
196
- if ( string . IsNullOrWhiteSpace ( name ) )
197
- throw new ArgumentException ( "Parameter names cannot be empty or white space." , nameof ( name ) ) ;
198
- Contract . EndContractBlock ( ) ;
199
-
200
- Params . Add ( new ( name , value , type , direction ) ) ;
201
- return ( TThis ) this ;
202
- }
203
+ => AddParam ( new ( name , value , type , direction ) ) ;
203
204
204
205
/// <inheritdoc cref="AddParam(string, object, TDbType, ParameterDirection)"/>
205
206
public TThis AddParam ( string name , object ? value , ParameterDirection direction = ParameterDirection . Input )
206
- {
207
- if ( name is null ) throw new ArgumentNullException ( nameof ( name ) ) ;
208
- if ( string . IsNullOrWhiteSpace ( name ) )
209
- throw new ArgumentException ( "Parameter names cannot be empty or white space." , nameof ( name ) ) ;
210
- Contract . EndContractBlock ( ) ;
211
-
212
- Params . Add ( new ( name , value ?? DBNull . Value , null , direction ) ) ;
213
- return ( TThis ) this ;
214
- }
207
+ => AddParam ( new ( name , value , null , direction ) ) ;
215
208
216
209
/// <inheritdoc cref="AddParam(string, object, TDbType, ParameterDirection)"/>
217
210
public TThis AddParam < T > ( string name , T ? value , TDbType ? type = null , ParameterDirection direction = ParameterDirection . Input )
218
211
where T : struct
219
- {
220
- if ( name is null ) throw new ArgumentNullException ( nameof ( name ) ) ;
221
- if ( string . IsNullOrWhiteSpace ( name ) )
222
- throw new ArgumentException ( "Parameter names cannot be empty or white space." , nameof ( name ) ) ;
223
- Contract . EndContractBlock ( ) ;
224
-
225
- Params . Add ( new ( name , value ?? ( object ) DBNull . Value , type , direction ) ) ;
226
- return ( TThis ) this ;
227
- }
212
+ => AddParam ( new ( name , value , type , direction ) ) ;
228
213
229
214
/// <inheritdoc cref="AddParam(string, object, TDbType, ParameterDirection)"/>
230
215
public TThis AddParam ( string name , string ? value , TDbType ? type = null , ParameterDirection direction = ParameterDirection . Input )
231
- {
232
- if ( name is null ) throw new ArgumentNullException ( nameof ( name ) ) ;
233
- if ( string . IsNullOrWhiteSpace ( name ) )
234
- throw new ArgumentException ( "Parameter names cannot be empty or white space." , nameof ( name ) ) ;
235
- Contract . EndContractBlock ( ) ;
236
-
237
- Params . Add ( new ( name , value ?? ( object ) DBNull . Value , type , direction ) ) ;
238
- return ( TThis ) this ;
239
- }
216
+ => AddParam ( new ( name , value , type , direction ) ) ;
240
217
241
218
/// <inheritdoc cref="AddParam(string, object, TDbType, ParameterDirection)"/>
242
219
public TThis AddParam ( string name , TDbType type , ParameterDirection direction = ParameterDirection . Input )
243
- {
244
- if ( name is null ) throw new ArgumentNullException ( nameof ( name ) ) ;
245
- if ( string . IsNullOrWhiteSpace ( name ) )
246
- throw new ArgumentException ( "Parameter names cannot be empty or white space." , nameof ( name ) ) ;
247
- Contract . EndContractBlock ( ) ;
248
-
249
- Params . Add ( new ( name , null , type , direction ) ) ;
250
- return ( TThis ) this ;
251
- }
220
+ => AddParam ( new ( name , null , type , direction ) ) ;
252
221
253
222
/// <inheritdoc cref="AddParam(string, object, TDbType, ParameterDirection)"/>
254
223
public TThis AddParam ( string name , ParameterDirection direction = ParameterDirection . Input )
255
- {
256
- if ( name is null ) throw new ArgumentNullException ( nameof ( name ) ) ;
257
- if ( string . IsNullOrWhiteSpace ( name ) )
258
- throw new ArgumentException ( "Parameter names cannot be empty or white space." , nameof ( name ) ) ;
259
- Contract . EndContractBlock ( ) ;
260
-
261
- Params . Add ( new ( name , null , null , direction ) ) ;
262
- return ( TThis ) this ;
263
- }
224
+ => AddParam ( new ( name , null , null , direction ) ) ;
264
225
265
226
/// <summary>
266
227
/// Adds a return parameter to the params list.
267
228
/// </summary>
268
229
/// <inheritdoc cref="AddParam(string, object, TDbType, ParameterDirection)"/>
269
230
public TThis AddReturnParam ( string name , TDbType type )
270
- {
271
- if ( name is null ) throw new ArgumentNullException ( nameof ( name ) ) ;
272
- if ( string . IsNullOrWhiteSpace ( name ) )
273
- throw new ArgumentException ( "Parameter names cannot be empty or white space." , nameof ( name ) ) ;
274
- Contract . EndContractBlock ( ) ;
275
-
276
- Params . Add ( new ( name , null , type , ParameterDirection . ReturnValue ) ) ;
277
- return ( TThis ) this ;
278
- }
231
+ => AddParam ( new ( name , null , type , ParameterDirection . ReturnValue ) ) ;
279
232
280
233
/// <inheritdoc cref="AddReturnParam(string, TDbType)"/>
281
234
public TThis AddReturnParam ( string name )
282
- {
283
- if ( name is null ) throw new ArgumentNullException ( nameof ( name ) ) ;
284
- if ( string . IsNullOrWhiteSpace ( name ) )
285
- throw new ArgumentException ( "Parameter names cannot be empty or white space." , nameof ( name ) ) ;
286
- Contract . EndContractBlock ( ) ;
287
-
288
- Params . Add ( new ( name , null , null , ParameterDirection . ReturnValue ) ) ;
289
- return ( TThis ) this ;
290
- }
235
+ => AddParam ( new ( name , null , null , ParameterDirection . ReturnValue ) ) ;
291
236
292
237
/// <summary>
293
238
/// Conditionally adds a parameter to the params list.
0 commit comments