2
2
using Plugin ;
3
3
using System ;
4
4
using System . Collections . Generic ;
5
+ using System . Linq ;
5
6
using static Microsoft . CodeAnalysis . CSharp . SyntaxFactory ;
6
7
using static System . String ;
7
8
@@ -15,6 +16,8 @@ public abstract class DbDriver(DotnetFramework dotnetFramework)
15
16
16
17
private HashSet < string > CsharpPrimitives { get ; } = [ "long" , "double" , "int" , "float" , "bool" , "DateTime" ] ;
17
18
19
+ protected abstract List < ColumnMapping > ColumnMappings { get ; }
20
+
18
21
public virtual UsingDirectiveSyntax [ ] GetUsingDirectives ( )
19
22
{
20
23
return
@@ -25,8 +28,6 @@ public virtual UsingDirectiveSyntax[] GetUsingDirectives()
25
28
] ;
26
29
}
27
30
28
- protected abstract List < ( string , Func < int , string > , HashSet < string > ) > GetColumnMapping ( ) ;
29
-
30
31
public string AddNullableSuffix ( string csharpType , bool notNull )
31
32
{
32
33
if ( notNull ) return csharpType ;
@@ -42,10 +43,10 @@ public string GetColumnType(Column column)
42
43
string GetTypeWithoutNullableSuffix ( )
43
44
{
44
45
var columnType = column . Type . Name . ToLower ( ) ;
45
- foreach ( var ( csharpType , _, dbTypes ) in GetColumnMapping ( ) )
46
+ foreach ( var columnMapping in ColumnMappings
47
+ . Where ( columnMapping => columnMapping . DbTypes . ContainsKey ( columnType ) ) )
46
48
{
47
- if ( dbTypes . Contains ( columnType ) )
48
- return csharpType ;
49
+ return columnMapping . CsharpType ;
49
50
}
50
51
throw new NotSupportedException ( $ "Unsupported column type: { column . Type . Name } ") ;
51
52
}
@@ -54,11 +55,23 @@ string GetTypeWithoutNullableSuffix()
54
55
public string GetColumnReader ( Column column , int ordinal )
55
56
{
56
57
var columnType = column . Type . Name . ToLower ( ) ;
57
- foreach ( var ( _, getDataReader , dbTypes ) in GetColumnMapping ( ) )
58
+ foreach ( var columnMapping in ColumnMappings
59
+ . Where ( columnMapping => columnMapping . DbTypes . ContainsKey ( columnType ) ) )
60
+ {
61
+ return columnMapping . ReaderFn ( ordinal ) ;
62
+ }
63
+ throw new NotSupportedException ( $ "Unsupported column type: { column . Type . Name } ") ;
64
+ }
65
+
66
+ public string ? GetColumnDbTypeOverride ( Column column )
67
+ {
68
+ var columnType = column . Type . Name . ToLower ( ) ;
69
+ foreach ( var columnMapping in ColumnMappings )
58
70
{
59
- if ( dbTypes . Contains ( columnType ) )
60
- return getDataReader ( ordinal ) ;
71
+ if ( columnMapping . DbTypes . TryGetValue ( columnType , out var dbTypeOverride ) )
72
+ return dbTypeOverride ;
61
73
}
74
+
62
75
throw new NotSupportedException ( $ "Unsupported column type: { column . Type . Name } ") ;
63
76
}
64
77
0 commit comments