Skip to content

Commit d34b6eb

Browse files
authored
Have removed all explicit class constraints and nothing blows up (#295)
All the unit tests still pass, however I have not added anything to them as there are loads of them and I don't want to go down the rabbit hole of verifying all same tests but with structs, also didn't run integration tests. However it's a start incase anyone else wants to pick it up.
1 parent a820fb8 commit d34b6eb

22 files changed

+231
-240
lines changed

DapperExtensions.Test/Mapper/AutoClassMapperFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void Sets_IdFirstPropertyEndingInIdWhenNoIdPropertyFound()
9191
Assert.IsTrue(map.ColumnName == "SomeId");
9292
}
9393

94-
private static AutoClassMapper<T> GetMapper<T>() where T : class
94+
private static AutoClassMapper<T> GetMapper<T>()
9595
{
9696
return new AutoClassMapper<T>();
9797
}
@@ -114,12 +114,12 @@ public void ReturnsProperResultsForExceptions()
114114
Assert.AreEqual("TheFoo", m.TableName);
115115
}
116116

117-
private static CustomAutoMapper<T> GetMapper<T>() where T : class
117+
private static CustomAutoMapper<T> GetMapper<T>()
118118
{
119119
return new CustomAutoMapper<T>();
120120
}
121121

122-
public class CustomAutoMapper<T> : AutoClassMapper<T> where T : class
122+
public class CustomAutoMapper<T> : AutoClassMapper<T>
123123
{
124124
public override void Table(string tableName)
125125
{

DapperExtensions.Test/Mapper/ClassMapperFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void Setup()
2323
{
2424
}
2525

26-
protected ClassMapper<T> GetMapper<T>() where T : class
26+
protected ClassMapper<T> GetMapper<T>()
2727
{
2828
return new ClassMapper<T>();
2929
}
@@ -400,7 +400,7 @@ public class Bar
400400
}
401401

402402
[ExcludeFromCodeCoverage]
403-
public class TestMapper<T> : ClassMapper<T> where T : class
403+
public class TestMapper<T> : ClassMapper<T>
404404
{
405405
public new MemberMap Map(Expression<Func<T, object>> expression)
406406
{

DapperExtensions.Test/Mapper/PluralizedAutoClassMapperFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void ReturnsProperPluralizationWhenWordIsUnpluralizable()
7575
Assert.AreEqual("equipment", m.TableName);
7676
}
7777

78-
private static PluralizedAutoClassMapper<T> GetMapper<T>() where T : class
78+
private static PluralizedAutoClassMapper<T> GetMapper<T>()
7979
{
8080
return new PluralizedAutoClassMapper<T>();
8181
}
@@ -100,12 +100,12 @@ public void ReturnsProperResultsForExceptions()
100100
Assert.AreEqual("People", m.TableName);
101101
}
102102

103-
private static CustomPluralizedMapper<T> GetMapper<T>() where T : class
103+
private static CustomPluralizedMapper<T> GetMapper<T>()
104104
{
105105
return new CustomPluralizedMapper<T>();
106106
}
107107

108-
public class CustomPluralizedMapper<T> : PluralizedAutoClassMapper<T> where T : class
108+
public class CustomPluralizedMapper<T> : PluralizedAutoClassMapper<T>
109109
{
110110
public override void Table(string tableName)
111111
{

DapperExtensions.Test/PredicatesFixture.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,16 @@ public void In_ReturnsSetupPredicate()
147147
Assert.AreEqual("Id", predicate.PropertyName);
148148
Assert.AreEqual(values, predicate.Collection);
149149
Assert.AreEqual(false, predicate.Not);
150-
}
151-
150+
}
151+
152152
[Test]
153153
public void BitEq_ReturnsSetupPredicate()
154154
{
155155
var predicate = Predicates.Field<PredicateTestEntity>(f => f.Id, Operator.BitEq, 1, false);
156156
Assert.AreEqual("Id", predicate.PropertyName);
157157
Assert.AreEqual(Operator.BitEq, predicate.Operator);
158158
Assert.AreEqual(1, predicate.Value);
159-
Assert.AreEqual(false, predicate.Not);
159+
Assert.AreEqual(false, predicate.Not);
160160
}
161161
}
162162

@@ -392,7 +392,7 @@ public void GetSql_ChainedProperty_ReturnsProperSql()
392392
sql.Should().Be("(y2.Id ** @Id_0)");
393393
}
394394

395-
protected Mock<FieldPredicate<T>> Setup<T>(string propertyName, Operator op, object value, bool not, DatabaseFunction databaseFunction = DatabaseFunction.None, string functionParameters = null) where T : class
395+
protected Mock<FieldPredicate<T>> Setup<T>(string propertyName, Operator op, object value, bool not, DatabaseFunction databaseFunction = DatabaseFunction.None, string functionParameters = null)
396396
{
397397
Configuration.Setup(m => m.GetMap(It.IsAny<Type>())).Returns(new AutoClassMapper<T>());
398398

@@ -483,7 +483,7 @@ public void GetSql_BothtPropertyWithDatabaseFunction_ReturnsProperSql()
483483
protected Mock<PropertyPredicate<T, T2>> Setup<T, T2>(string propertyName, Operator op, string propertyName2, bool not,
484484
DatabaseFunction leftDatabaseFunction = DatabaseFunction.None, string leftFunctionParameters = null,
485485
DatabaseFunction rightDatabaseFunction = DatabaseFunction.None, string rightFunctionParameters = null)
486-
where T : class
486+
487487
where T2 : class
488488
{
489489
Mock<PropertyPredicate<T, T2>> predicate = new Mock<PropertyPredicate<T, T2>>();
@@ -539,7 +539,7 @@ public void GetSql_Not_ReturnsProperSql()
539539
}
540540

541541
protected Mock<BetweenPredicate<T>> Setup<T>(string propertyName, object value1, object value2, bool not)
542-
where T : class
542+
543543
{
544544
Configuration.Setup(m => m.GetMap(It.IsAny<Type>())).Returns(new AutoClassMapper<T>());
545545

@@ -706,7 +706,7 @@ public void GetClassMapper_ReturnsMap()
706706
Assert.AreEqual(classMap.Object, result);
707707
}
708708

709-
protected Mock<ExistsPredicate<T>> Setup<T>(IPredicate predicate, IClassMapper classMap, bool not) where T : class
709+
protected Mock<ExistsPredicate<T>> Setup<T>(IPredicate predicate, IClassMapper classMap, bool not)
710710
{
711711
Configuration.Setup(m => m.GetMap(It.IsAny<Type>())).Returns(new AutoClassMapper<T>());
712712

@@ -759,7 +759,7 @@ public void GetSql_Not_ReturnsProperSql()
759759
}
760760

761761
protected Mock<InPredicate<T>> Setup<T>(string propertyName, bool not, params long[] values)
762-
where T : class
762+
763763
{
764764
Configuration.Setup(m => m.GetMap(It.IsAny<Type>())).Returns(new AutoClassMapper<T>());
765765

DapperExtensions/DapperAsyncExtensions.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static IDapperExtensionsConfiguration Configure(this Type defaultMapper,
161161
/// <summary>
162162
/// Executes a query using the specified predicate, returning an integer that represents the number of rows that match the query.
163163
/// </summary>
164-
public static async Task<int> CountAsync<T>(this IDbConnection connection, object predicate = null, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
164+
public static async Task<int> CountAsync<T>(this IDbConnection connection, object predicate = null, IDbTransaction transaction = null, int? commandTimeout = null)
165165
{
166166
return await Instance.CountAsync<T>(connection, predicate, transaction, commandTimeout).ConfigureAwait(false);
167167
}
@@ -170,7 +170,7 @@ public static async Task<int> CountAsync<T>(this IDbConnection connection, objec
170170
/// Executes a query for the specified id, returning the data typed as per T.
171171
/// </summary>
172172
public static async Task<T> GetAsync<T>(this IDbConnection connection, dynamic id, IDbTransaction transaction = null,
173-
int? commandTimeout = null, bool buffered = false) where T : class
173+
int? commandTimeout = null, bool buffered = false)
174174
{
175175
return await Instance.GetAsync<T>(connection, id, transaction, commandTimeout, buffered, null).ConfigureAwait(false);
176176
}
@@ -192,7 +192,7 @@ public static async Task<TOut> GetPartialAsync<TIn, TOut>(this IDbConnection con
192192
/// Executes a select query using the specified predicate, returning an IEnumerable data typed as per T.
193193
/// </summary>
194194
public static async Task<IEnumerable<T>> GetListAsync<T>(this IDbConnection connection, object predicate = null, IList<ISort> sort = null,
195-
IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false) where T : class
195+
IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false)
196196
{
197197
return await Instance.GetListAsync<T>(connection, predicate, sort, transaction, commandTimeout, buffered, null).ConfigureAwait(false);
198198
}
@@ -214,15 +214,15 @@ public static async Task<IEnumerable<TOut>> GetPartialListAsync<TIn, TOut>(this
214214
/// Contains Slapper.Automaper
215215
/// </summary>
216216
public static async Task<IEnumerable<T>> GetListAutoMapAsync<T>(this IDbConnection connection, object predicate = null, IList<ISort> sort = null,
217-
IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false, IList<IProjection> colsToSelect = null) where T : class
217+
IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false, IList<IProjection> colsToSelect = null)
218218
{
219219
return await Instance.GetListAutoMapAsync<T>(connection, predicate, sort, transaction, commandTimeout, buffered, colsToSelect).ConfigureAwait(false);
220220
}
221221

222222
/// <summary>
223223
/// Executes an insert query for the specified entity.
224224
/// </summary>
225-
public static Task InsertAsync<T>(this IDbConnection connection, IEnumerable<T> entities, IDbTransaction transaction = null, int? commandTimeout = default) where T : class
225+
public static Task InsertAsync<T>(this IDbConnection connection, IEnumerable<T> entities, IDbTransaction transaction = null, int? commandTimeout = default)
226226
{
227227
return Instance.InsertAsync(connection, entities, transaction, commandTimeout);
228228
}
@@ -233,7 +233,7 @@ public static Task InsertAsync<T>(this IDbConnection connection, IEnumerable<T>
233233
/// If the entity has a composite key, an IDictionary&lt;string, object&gt; is returned with the key values.
234234
/// The key value for the entity will also be updated if the KeyType is a Guid or Identity.
235235
/// </summary>
236-
public static Task<dynamic> InsertAsync<T>(this IDbConnection connection, T entity, IDbTransaction transaction = null, int? commandTimeout = default) where T : class
236+
public static Task<dynamic> InsertAsync<T>(this IDbConnection connection, T entity, IDbTransaction transaction = null, int? commandTimeout = default)
237237
{
238238
return Instance.InsertAsync(connection, entity, transaction, commandTimeout);
239239
}
@@ -242,7 +242,7 @@ public static Task<dynamic> InsertAsync<T>(this IDbConnection connection, T enti
242242
/// Executes an update query for the specified entity.
243243
/// </summary>
244244
public static Task<bool> UpdateAsync<T>(this IDbConnection connection, T entity, IDbTransaction transaction = null,
245-
int? commandTimeout = null, bool ignoreAllKeyProperties = false) where T : class
245+
int? commandTimeout = null, bool ignoreAllKeyProperties = false)
246246
{
247247
return Instance.UpdateAsync(connection, entity, transaction, commandTimeout, ignoreAllKeyProperties, null);
248248
}
@@ -260,15 +260,15 @@ public static Task<bool> UpdatePartialAsync<TIn, TOut>(this IDbConnection connec
260260
/// <summary>
261261
/// Executes a delete query for the specified entity.
262262
/// </summary>
263-
public static Task<bool> DeleteAsync<T>(this IDbConnection connection, T entity, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
263+
public static Task<bool> DeleteAsync<T>(this IDbConnection connection, T entity, IDbTransaction transaction = null, int? commandTimeout = null)
264264
{
265265
return Instance.DeleteAsync(connection, entity, transaction, commandTimeout);
266266
}
267267

268268
/// <summary>
269269
/// Executes a delete query using the specified predicate.
270270
/// </summary>
271-
public static Task<bool> DeleteAsync<T>(this IDbConnection connection, object predicate, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
271+
public static Task<bool> DeleteAsync<T>(this IDbConnection connection, object predicate, IDbTransaction transaction = null, int? commandTimeout = null)
272272
{
273273
return Instance.DeleteAsync(connection, predicate, transaction, commandTimeout);
274274
}
@@ -278,7 +278,7 @@ public static Task<bool> DeleteAsync<T>(this IDbConnection connection, object pr
278278
/// Data returned is dependent upon the specified page and resultsPerPage.
279279
/// </summary>
280280
public static async Task<IEnumerable<T>> GetPageAsync<T>(this IDbConnection connection, object predicate = null, IList<ISort> sort = null, int page = 1,
281-
int resultsPerPage = 10, IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false) where T : class
281+
int resultsPerPage = 10, IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false)
282282
{
283283
return await Instance.GetPageAsync<T>(connection, predicate, sort, page, resultsPerPage, transaction, commandTimeout, buffered, null).ConfigureAwait(false);
284284
}
@@ -307,7 +307,7 @@ public static async Task<IEnumerable<TOut>> GetPartialPageAsync<TIn, TOut>(this
307307
/// Contains Slapper.Automaper
308308
/// </summary>
309309
public static async Task<IEnumerable<T>> GetPageAutoMapAsync<T>(this IDbConnection connection, object predicate = null, IList<ISort> sort = null, int page = 1,
310-
int resultsPerPage = 10, IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false, IList<IProjection> colsToSelect = null) where T : class
310+
int resultsPerPage = 10, IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false, IList<IProjection> colsToSelect = null)
311311
{
312312
return await Instance.GetPageAutoMapAsync<T>(connection, predicate, sort, page, resultsPerPage, transaction, commandTimeout, buffered, colsToSelect).ConfigureAwait(false);
313313
}
@@ -317,7 +317,7 @@ public static async Task<IEnumerable<T>> GetPageAutoMapAsync<T>(this IDbConnecti
317317
/// Data returned is dependent upon the specified firstResult and maxResults.
318318
/// </summary>
319319
public static async Task<IEnumerable<T>> GetSetAsync<T>(this IDbConnection connection, object predicate = null, IList<ISort> sort = null, int firstResult = 1,
320-
int maxResults = 10, IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false) where T : class
320+
int maxResults = 10, IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false)
321321
{
322322
return await Instance.GetSetAsync<T>(connection, predicate, sort, firstResult, maxResults, transaction, commandTimeout, buffered, null).ConfigureAwait(false);
323323
}
@@ -367,7 +367,7 @@ public static async Task<Guid> GetNextGuid()
367367
/// Gets the appropriate mapper for the specified type T.
368368
/// If the mapper for the type is not yet created, a new mapper is generated from the mapper type specifed by DefaultMapper.
369369
/// </summary>
370-
public static async Task<IClassMapper> GetMap<T>() where T : class
370+
public static async Task<IClassMapper> GetMap<T>()
371371
{
372372
return await Task.FromResult(_configuration.GetMap<T>());
373373
}

0 commit comments

Comments
 (0)