Optimize the code

This commit is contained in:
sunkaixuan 2025-06-26 10:34:43 +08:00
parent 148b299995
commit 5fb63604cf
2 changed files with 8 additions and 4 deletions

View File

@ -203,7 +203,7 @@ namespace SqlSugar
{ {
using (dataReader) using (dataReader)
{ {
if (type.Name.StartsWith("KeyValuePair")) if (UtilMethods.IsKeyValuePairType(type))
{ {
return GetKeyValueList<T>(type, dataReader); return GetKeyValueList<T>(type, dataReader);
} }
@ -231,7 +231,7 @@ namespace SqlSugar
{ {
using (dataReader) using (dataReader)
{ {
if (type.Name.StartsWith("KeyValuePair")) if (UtilMethods.IsKeyValuePairType(type))
{ {
return await GetKeyValueListAsync<T>(type, dataReader); return await GetKeyValueListAsync<T>(type, dataReader);
} }
@ -256,7 +256,7 @@ namespace SqlSugar
} }
public virtual List<T> DataReaderToListNoUsing<T>(Type type, IDataReader dataReader) public virtual List<T> DataReaderToListNoUsing<T>(Type type, IDataReader dataReader)
{ {
if (type.Name.StartsWith("KeyValuePair")) if (UtilMethods.IsKeyValuePairType(type))
{ {
return GetKeyValueList<T>(type, dataReader); return GetKeyValueList<T>(type, dataReader);
} }
@ -275,7 +275,7 @@ namespace SqlSugar
} }
public virtual Task<List<T>> DataReaderToListNoUsingAsync<T>(Type type, IDataReader dataReader) public virtual Task<List<T>> DataReaderToListNoUsingAsync<T>(Type type, IDataReader dataReader)
{ {
if (type.Name.StartsWith("KeyValuePair")) if (UtilMethods.IsKeyValuePairType(type))
{ {
return GetKeyValueListAsync<T>(type, dataReader); return GetKeyValueListAsync<T>(type, dataReader);
} }

View File

@ -18,6 +18,10 @@ namespace SqlSugar
{ {
public class UtilMethods public class UtilMethods
{ {
public static bool IsKeyValuePairType(Type type)
{
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>);
}
public static DataTable ConvertDateTimeOffsetToDateTime(DataTable table) public static DataTable ConvertDateTimeOffsetToDateTime(DataTable table)
{ {
if (!table.Columns.Cast<DataColumn>().Any(it => it.DataType == typeof(DateTimeOffset))) if (!table.Columns.Cast<DataColumn>().Any(it => it.DataType == typeof(DateTimeOffset)))