diff --git a/Dapper.Contrib/SqlMapperExtensions.Async.cs b/Dapper.Contrib/SqlMapperExtensions.Async.cs index c93e39a48..cb1103fb7 100644 --- a/Dapper.Contrib/SqlMapperExtensions.Async.cs +++ b/Dapper.Contrib/SqlMapperExtensions.Async.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data; using System.Linq; @@ -143,24 +143,7 @@ public static Task InsertAsync(this IDbConnection connection, T entityTo sqlAdapter ??= GetFormatter(connection); var isList = false; - if (type.IsArray) - { - isList = true; - type = type.GetElementType(); - } - else if (type.IsGenericType) - { - var typeInfo = type.GetTypeInfo(); - bool implementsGenericIEnumerableOrIsGenericIEnumerable = - typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) || - typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>); - - if (implementsGenericIEnumerableOrIsGenericIEnumerable) - { - isList = true; - type = type.GetGenericArguments()[0]; - } - } + isList = IsArrayAndGetElementType(ref type); var name = GetTableName(type); var sbColumnList = new StringBuilder(null); @@ -215,22 +198,7 @@ public static async Task UpdateAsync(this IDbConnection connection, T e var type = typeof(T); - if (type.IsArray) - { - type = type.GetElementType(); - } - else if (type.IsGenericType) - { - var typeInfo = type.GetTypeInfo(); - bool implementsGenericIEnumerableOrIsGenericIEnumerable = - typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) || - typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>); - - if (implementsGenericIEnumerableOrIsGenericIEnumerable) - { - type = type.GetGenericArguments()[0]; - } - } + _ = IsArrayAndGetElementType(ref type); var keyProperties = KeyPropertiesCache(type).ToList(); var explicitKeyProperties = ExplicitKeyPropertiesCache(type); @@ -284,22 +252,7 @@ public static async Task DeleteAsync(this IDbConnection connection, T e var type = typeof(T); - if (type.IsArray) - { - type = type.GetElementType(); - } - else if (type.IsGenericType) - { - var typeInfo = type.GetTypeInfo(); - bool implementsGenericIEnumerableOrIsGenericIEnumerable = - typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) || - typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>); - - if (implementsGenericIEnumerableOrIsGenericIEnumerable) - { - type = type.GetGenericArguments()[0]; - } - } + _ = IsArrayAndGetElementType(ref type); var keyProperties = KeyPropertiesCache(type); var explicitKeyProperties = ExplicitKeyPropertiesCache(type);