@@ -39,11 +39,11 @@ internal override unsafe object GetValue(ulong offset, Type targetType)
39
39
switch ( DuckDBType )
40
40
{
41
41
case DuckDBType . List :
42
- {
43
- var listData = ( DuckDBListEntry * ) DataPointer + offset ;
42
+ {
43
+ var listData = ( DuckDBListEntry * ) DataPointer + offset ;
44
44
45
- return GetList ( targetType , listData ->Offset , listData ->Length ) ;
46
- }
45
+ return GetList ( targetType , listData ->Offset , listData ->Length ) ;
46
+ }
47
47
case DuckDBType . Array :
48
48
return GetList ( targetType , offset * arraySize , arraySize ) ;
49
49
default :
@@ -61,57 +61,50 @@ private unsafe object GetList(Type returnType, ulong listOffset, ulong length)
61
61
?? throw new ArgumentException ( $ "The type '{ returnType . Name } ' specified in parameter { nameof ( returnType ) } cannot be instantiated as an IList.") ;
62
62
63
63
//Special case for specific types to avoid boxing
64
- switch ( list )
64
+ return list switch
65
65
{
66
- case List < int > theList :
67
- return BuildList < int > ( theList ) ;
68
- case List < int ? > theList :
69
- return BuildList < int ? > ( theList ) ;
70
- case List < float > theList :
71
- return BuildList < float > ( theList ) ;
72
- case List < float ? > theList :
73
- return BuildList < float ? > ( theList ) ;
74
- case List < double > theList :
75
- return BuildList < double > ( theList ) ;
76
- case List < double ? > theList :
77
- return BuildList < double ? > ( theList ) ;
78
- case List < decimal > theList :
79
- return BuildList < decimal > ( theList ) ;
80
- case List < decimal ? > theList :
81
- return BuildList < decimal ? > ( theList ) ;
82
- }
83
-
84
- var targetType = nullableType ?? listType ;
66
+ List < int > theList => BuildList < int > ( theList ) ,
67
+ List < int ? > theList => BuildList < int ? > ( theList ) ,
68
+ List < float > theList => BuildList < float > ( theList ) ,
69
+ List < float ? > theList => BuildList < float ? > ( theList ) ,
70
+ List < double > theList => BuildList < double > ( theList ) ,
71
+ List < double ? > theList => BuildList < double ? > ( theList ) ,
72
+ List < decimal > theList => BuildList < decimal > ( theList ) ,
73
+ List < decimal ? > theList => BuildList < decimal ? > ( theList ) ,
74
+ _ => BuildListCommon ( list , nullableType ?? listType )
75
+ } ;
85
76
86
- for ( ulong i = 0 ; i < length ; i ++ )
77
+ List < T > BuildList < T > ( List < T > result )
87
78
{
88
- var childOffset = listOffset + i ;
89
- if ( listDataReader . IsValid ( childOffset ) )
90
- {
91
- var item = listDataReader . GetValue ( childOffset , targetType ) ;
92
- list . Add ( item ) ;
93
- }
94
- else
79
+ for ( ulong i = 0 ; i < length ; i ++ )
95
80
{
96
- list . Add ( allowNulls ? null : throw new InvalidCastException ( "The list contains null value" ) ) ;
81
+ var childOffset = listOffset + i ;
82
+ if ( listDataReader . IsValid ( childOffset ) )
83
+ {
84
+ var item = listDataReader . GetValue < T > ( childOffset ) ;
85
+ result . Add ( item ) ;
86
+ }
87
+ else
88
+ {
89
+ result . Add ( allowNulls ? default ! : throw new InvalidCastException ( "The list contains null value" ) ) ;
90
+ }
97
91
}
92
+ return result ;
98
93
}
99
94
100
- return list ;
101
-
102
- List < T > BuildList < T > ( List < T > result )
95
+ IList BuildListCommon ( IList result , Type targetType )
103
96
{
104
97
for ( ulong i = 0 ; i < length ; i ++ )
105
98
{
106
99
var childOffset = listOffset + i ;
107
100
if ( listDataReader . IsValid ( childOffset ) )
108
101
{
109
- var item = listDataReader . GetValue < T > ( childOffset ) ;
102
+ var item = listDataReader . GetValue ( childOffset , targetType ) ;
110
103
result . Add ( item ) ;
111
104
}
112
105
else
113
106
{
114
- result . Add ( allowNulls ? default ! : throw new InvalidCastException ( "The list contains null value" ) ) ;
107
+ result . Add ( allowNulls ? null : throw new InvalidCastException ( "The list contains null value" ) ) ;
115
108
}
116
109
}
117
110
return result ;
0 commit comments