@@ -31,7 +31,7 @@ internal static IEnumerable<T> Concat<T>(T first, ICollection<T> remaining)
31
31
/// to the <paramref name="target"/> span
32
32
/// with any <see cref="DBNull"/> values converted to <see langword="null"/>.
33
33
/// </summary>
34
- public static Span < object ? > CopyToWithDbNullAsNull ( this ReadOnlySpan < object ? > values , Span < object ? > target )
34
+ public static Span < object ? > CopyToDBNullAsNull ( this ReadOnlySpan < object ? > values , Span < object ? > target )
35
35
{
36
36
int len = values . Length ;
37
37
object ? [ ] result = new object ? [ len ] ;
@@ -41,9 +41,18 @@ internal static IEnumerable<T> Concat<T>(T first, ICollection<T> remaining)
41
41
return result ;
42
42
}
43
43
44
- /// <inheritdoc cref="CopyToWithDbNullAsNull(ReadOnlySpan{object?}, Span{object?})"/>
45
- public static Span < object ? > CopyToWithDbNullAsNull ( this Span < object ? > values , Span < object ? > target )
46
- => CopyToWithDbNullAsNull ( ( ReadOnlySpan < object ? > ) values , target ) ;
44
+ /// <inheritdoc cref="CopyToDBNullAsNull(ReadOnlySpan{object?}, Span{object?})"/>
45
+ public static Span < object ? > CopyToDBNullAsNull ( this Span < object ? > values , Span < object ? > target )
46
+ => CopyToDBNullAsNull ( ( ReadOnlySpan < object ? > ) values , target ) ;
47
+
48
+
49
+ /// <inheritdoc cref="CopyToDBNullAsNull(ReadOnlySpan{object?}, Span{object?})"/>
50
+ public static Span < object ? > CopyToDBNullAsNull ( this ReadOnlySpan < object ? > values , Memory < object ? > target )
51
+ => CopyToDBNullAsNull ( values , target . Span ) ;
52
+
53
+ /// <inheritdoc cref="CopyToDBNullAsNull(ReadOnlySpan{object?}, Span{object?})"/>
54
+ public static Span < object ? > CopyToDBNullAsNull ( this Span < object ? > values , Memory < object ? > target )
55
+ => CopyToDBNullAsNull ( ( ReadOnlySpan < object ? > ) values , target . Span ) ;
47
56
48
57
/// <summary>
49
58
/// Any <see cref="DBNull"/> values are yielded as null.
@@ -70,7 +79,7 @@ internal static IEnumerable<T> Concat<T>(T first, ICollection<T> remaining)
70
79
Contract . EndContractBlock ( ) ;
71
80
72
81
object ? [ ] result = new object ? [ values . Length ] ;
73
- CopyToWithDbNullAsNull ( values . AsSpan ( ) , result . AsSpan ( ) ) ;
82
+ CopyToDBNullAsNull ( values . AsSpan ( ) , result . AsSpan ( ) ) ;
74
83
return result ;
75
84
}
76
85
@@ -81,7 +90,7 @@ internal static IEnumerable<T> Concat<T>(T first, ICollection<T> remaining)
81
90
public static object ? [ ] DBNullToNullCopy ( this ReadOnlySpan < object ? > values )
82
91
{
83
92
object ? [ ] result = new object ? [ values . Length ] ;
84
- DBNullToNullCopy ( values , result . AsSpan ( ) ) ;
93
+ CopyToDBNullAsNull ( values , result . AsSpan ( ) ) ;
85
94
return result ;
86
95
}
87
96
@@ -94,7 +103,14 @@ internal static IEnumerable<T> Concat<T>(T first, ICollection<T> remaining)
94
103
/// </summary>
95
104
/// <param name="values">The source values.</param>
96
105
public static Span < object ? > ReplaceDBNullWithNull ( this Span < object ? > values )
97
- => DBNullToNullCopy ( values , values ) ;
106
+ => CopyToDBNullAsNull ( values , values ) ;
107
+
108
+ /// <inheritdoc cref="ReplaceDBNullWithNull(Span{object?})"/>
109
+ public static Memory < object ? > ReplaceDBNullWithNull ( this Memory < object ? > values )
110
+ {
111
+ CopyToDBNullAsNull ( values . Span , values . Span ) ;
112
+ return values ;
113
+ }
98
114
99
115
/// <inheritdoc cref="ReplaceDBNullWithNull(Span{object?})"/>
100
116
public static object ? [ ] ReplaceDBNullWithNull ( this object ? [ ] values )
@@ -106,6 +122,30 @@ internal static IEnumerable<T> Concat<T>(T first, ICollection<T> remaining)
106
122
return values ;
107
123
}
108
124
125
+ /// <inheritdoc cref="ReplaceDBNullWithNull(Span{object?})"/>
126
+ public static List < object ? > ReplaceDBNullWithNull ( this List < object ? > values )
127
+ {
128
+ if ( values is null ) throw new ArgumentNullException ( nameof ( values ) ) ;
129
+ Contract . EndContractBlock ( ) ;
130
+
131
+ #if NET8_0_OR_GREATER
132
+ var span = System . Runtime . InteropServices . CollectionsMarshal . AsSpan ( values ) ;
133
+ for ( int i = 0 ; i < span . Length ; i ++ )
134
+ {
135
+ ref object ? item = ref span [ i ] ;
136
+ if ( item == DBNull . Value ) item = null ;
137
+ }
138
+ #else
139
+ int count = values . Count ;
140
+ for ( int i = 0 ; i < count ; i ++ )
141
+ {
142
+ if ( values [ i ] == DBNull . Value ) values [ i ] = null ;
143
+ }
144
+ #endif
145
+
146
+ return values ;
147
+ }
148
+
109
149
/// <summary>
110
150
/// Generic enumerable extension for <see cref="DataColumnCollection"/>.
111
151
/// </summary>
@@ -149,7 +189,11 @@ static IEnumerable<DataRow> AsEnumerableCore(DataRowCollection rows)
149
189
. Results ( table , clearSourceTable ) ;
150
190
151
191
/// <inheritdoc cref="To{T}(DataTable, IEnumerable{KeyValuePair{string, string?}}?, bool)"/>
192
+ #if NET8_0_OR_GREATER
193
+ public static IEnumerable < T > To < T > ( this DataTable table , params IEnumerable < ( string Field , string ? Column ) > fieldMappingOverrides ) where T : new ( )
194
+ #else
152
195
public static IEnumerable < T > To < T > ( this DataTable table , params ( string Field , string ? Column ) [ ] fieldMappingOverrides ) where T : new ( )
196
+ #endif
153
197
=> Transformer < T >
154
198
. Create ( fieldMappingOverrides )
155
199
. Results ( table , false ) ;
0 commit comments