@@ -239,5 +239,41 @@ public static bool TryGetTimeSpan(this DbDataReader rs, int ordinal, out TimeSpa
239239 value = default ;
240240 return false ;
241241 }
242+
243+ public static object [ ] GetValues ( this DbDataReader rs , System . Type [ ] types )
244+ {
245+ if ( types . Length != rs . FieldCount )
246+ {
247+ throw new InvalidOperationException ( "Exptected number of types does not match the number of fields." ) ;
248+ }
249+
250+ var values = new object [ rs . FieldCount ] ;
251+
252+ for ( var i = 0 ; i < rs . FieldCount ; i ++ )
253+ {
254+ var typeCode = System . Type . GetTypeCode ( types [ i ] ) ;
255+
256+ values [ i ] = typeCode switch
257+ {
258+ TypeCode . Boolean => rs . GetBoolean ( i ) ,
259+ TypeCode . Char => rs . GetChar ( i ) ,
260+ TypeCode . Byte => rs . GetByte ( i ) ,
261+ TypeCode . Int16 => rs . GetInt16 ( i ) ,
262+ TypeCode . Int32 => rs . GetInt32 ( i ) ,
263+ TypeCode . Int64 => rs . GetInt64 ( i ) ,
264+ TypeCode . Single => rs . GetFloat ( i ) ,
265+ TypeCode . Double => rs . GetDouble ( i ) ,
266+ TypeCode . Decimal => rs . GetDecimal ( i ) ,
267+ TypeCode . DateTime => rs . GetDateTime ( i ) ,
268+ TypeCode . String => rs . GetString ( i ) ,
269+ TypeCode . UInt16 => ( ushort ) rs [ i ] ,
270+ TypeCode . UInt32 => ( uint ) rs [ i ] ,
271+ TypeCode . UInt64 => ( ulong ) rs [ i ] ,
272+ _ => rs [ i ]
273+ } ;
274+ }
275+
276+ return values ;
277+ }
242278 }
243279}
0 commit comments