13
13
var schemaCollections = deserializer . Deserialize < List < Schema > > ( reader ) ;
14
14
15
15
using var codeWriter = new StreamWriter ( @"..\..\..\..\..\src\MySqlConnector\Core\SchemaProvider.g.cs" ) ;
16
- codeWriter . Write ( @"// DO NOT EDIT - generated by SchemaCollectionGenerator.cs
17
- #nullable enable
18
- using MySqlConnector.Protocol.Serialization;
19
- using MySqlConnector.Utilities;
16
+ codeWriter . WriteLine ( """
17
+ // DO NOT EDIT - generated by SchemaCollectionGenerator.cs
18
+ #nullable enable
19
+ using MySqlConnector.Protocol.Serialization;
20
+ using MySqlConnector.Utilities;
20
21
21
- namespace MySqlConnector.Core;
22
+ namespace MySqlConnector.Core;
22
23
23
- internal sealed partial class SchemaProvider
24
- {
25
- public async ValueTask<DataTable> GetSchemaAsync(IOBehavior ioBehavior, string collectionName, string?[]? restrictionValues, CancellationToken cancellationToken)
24
+ internal sealed partial class SchemaProvider
26
25
{
27
- if (collectionName is null)
28
- throw new ArgumentNullException(nameof(collectionName));
26
+ public async ValueTask<DataTable> GetSchemaAsync(IOBehavior ioBehavior, string collectionName, string?[]? restrictionValues, CancellationToken cancellationToken)
27
+ {
28
+ if (collectionName is null)
29
+ throw new ArgumentNullException(nameof(collectionName));
29
30
30
- var dataTable = new DataTable(collectionName);
31
- " ) ;
32
- string elseIf = "if" ;
31
+ var dataTable = new DataTable(collectionName);
32
+ "" ") ;
33
+ var elseIf = "if" ;
33
34
foreach ( var schema in schemaCollections )
34
35
{
35
- codeWriter . Write ( @$ " { elseIf } (string.Equals(collectionName, ""{ schema . Name } "", StringComparison.OrdinalIgnoreCase))
36
- await Fill{ schema . Name } Async(ioBehavior, dataTable, restrictionValues, cancellationToken).ConfigureAwait(false);
37
- " ) ;
36
+ codeWriter . WriteLine ( $ """
37
+ { elseIf } (string.Equals(collectionName, "{ schema . Name } ", StringComparison.OrdinalIgnoreCase))
38
+ await Fill{ schema . Name } Async(ioBehavior, dataTable, restrictionValues, cancellationToken).ConfigureAwait(false);
39
+ """ ) ;
38
40
elseIf = "else if" ;
39
41
}
40
- codeWriter . Write ( @" else
41
- throw new ArgumentException(""Invalid collection name: '"" + collectionName + ""'."", nameof(collectionName));
42
+ codeWriter . WriteLine ( """
43
+ else
44
+ throw new ArgumentException("Invalid collection name: '" + collectionName + "'.", nameof(collectionName));
42
45
43
- return dataTable;
44
- }
46
+ return dataTable;
47
+ }
45
48
46
- " ) ;
49
+ "" ") ;
47
50
48
51
foreach ( var schema in schemaCollections )
49
52
{
50
53
var isAsync = schema . Table is not null ;
51
54
var supportsRestrictions = schema . Restrictions is { Count : > 0 } ;
52
- codeWriter . Write ( $@ " private { ( isAsync ? "async " : "" ) } Task Fill{ schema . Name } Async(IOBehavior ioBehavior, DataTable dataTable, string?[]? restrictionValues, CancellationToken cancellationToken)
53
- {{
54
- " ) ;
55
+ codeWriter . WriteLine ( $$ """
56
+ private {{ ( isAsync ? "async " : "" ) }} Task Fill{{ schema . Name }} Async(IOBehavior ioBehavior, DataTable dataTable, string?[]? restrictionValues, CancellationToken cancellationToken)
57
+ {
58
+ """ ) ;
55
59
if ( ! supportsRestrictions )
56
60
{
57
- codeWriter . Write ( $@ " if (restrictionValues is not null)
58
- throw new ArgumentException(""restrictionValues is not supported for schema '{ schema . Name } '."", nameof(restrictionValues));
59
- " ) ;
61
+ codeWriter . WriteLine ( $ """
62
+ if (restrictionValues is not null)
63
+ throw new ArgumentException("restrictionValues is not supported for schema '{ schema . Name } '.", nameof(restrictionValues));
64
+ """ ) ;
60
65
}
61
66
else
62
67
{
63
- codeWriter . Write ( $@ " if (restrictionValues is {{ Length: > { schema . Restrictions ! . Count } }})
64
- throw new ArgumentException(""More than { schema . Restrictions . Count } restrictionValues are not supported for schema '{ schema . Name } '."", nameof(restrictionValues));
65
- " ) ;
68
+ codeWriter . WriteLine ( $$ """
69
+ if (restrictionValues is { Length: > {{ schema . Restrictions ! . Count }} })
70
+ throw new ArgumentException("More than {{ schema . Restrictions . Count }} restrictionValues are not supported for schema '{{ schema . Name }} '.", nameof(restrictionValues));
71
+ """ ) ;
66
72
}
67
73
68
- codeWriter . Write ( $@ "
69
- dataTable.Columns.AddRange(new DataColumn[]
70
- {{
71
- " ) ;
74
+ codeWriter . WriteLine ( """
75
+
76
+ dataTable.Columns.AddRange(new DataColumn[]
77
+ {
78
+ """ ) ;
72
79
foreach ( var column in schema . Columns )
73
80
{
74
- codeWriter . Write ( $@ " new(""{ column . Name } "", typeof({ column . Type } )),
75
- " ) ;
81
+ codeWriter . WriteLine ( $ """
82
+ new("{ column . Name } ", typeof({ column . Type } )),
83
+ """ ) ;
76
84
}
77
- codeWriter . Write ( $@ " }});
85
+ codeWriter . WriteLine ( """
86
+ });
78
87
79
- " ) ;
88
+ "" ") ;
80
89
if ( schema . Table is string table )
81
90
{
82
91
if ( supportsRestrictions )
83
92
{
84
- codeWriter . Write ( $@ " var columns = new List<KeyValuePair<string, string>>();
85
- if (restrictionValues is not null)
86
- {{
87
- " ) ;
93
+ codeWriter . WriteLine ( """
94
+ var columns = new List<KeyValuePair<string, string>>();
95
+ if (restrictionValues is not null)
96
+ {
97
+ """ ) ;
88
98
for ( var i = 0 ; i < schema . Restrictions ! . Count ; i ++ )
89
99
{
90
100
if ( ! schema . Columns . Any ( x => x . Name == schema . Restrictions [ i ] . Default ) )
91
101
throw new InvalidOperationException ( "Restriction.Default must match a Column Name" ) ;
92
- codeWriter . Write ( $@ " if (restrictionValues.Length > { i } && !string.IsNullOrEmpty(restrictionValues[{ i } ]))
93
- columns.Add(new(""{ schema . Restrictions [ i ] . Default } "", restrictionValues[{ i } ]!));
94
- " ) ;
102
+ codeWriter . WriteLine ( $ """
103
+ if (restrictionValues.Length > { i } && !string.IsNullOrEmpty(restrictionValues[{ i } ]))
104
+ columns.Add(new("{ schema . Restrictions [ i ] . Default } ", restrictionValues[{ i } ]!));
105
+ """ ) ;
95
106
}
96
- codeWriter . Write ( @" }
107
+ codeWriter . WriteLine ( """
108
+ }
97
109
98
- " ) ;
110
+ "" ") ;
99
111
}
100
112
101
- codeWriter . Write ( @$ " await FillDataTableAsync(ioBehavior, dataTable, ""{ table } "", { ( supportsRestrictions ? "columns," : "null," ) } cancellationToken).ConfigureAwait(false);") ;
113
+ codeWriter . Write ( $ """
114
+ await FillDataTableAsync(ioBehavior, dataTable, "{ table } ", { ( supportsRestrictions ? "columns," : "null," ) } cancellationToken).ConfigureAwait(false);
115
+ """ ) ;
102
116
}
103
117
else if ( schema . Name == "MetaDataCollections" )
104
118
{
105
119
foreach ( var schemaCollection in schemaCollections )
106
120
{
107
- codeWriter . Write ( $@ " dataTable.Rows.Add(""{ schemaCollection . Name } "", { schemaCollection . Restrictions ? . Count ?? 0 } , { schemaCollection . IdentifierPartCount } );
108
- " ) ;
121
+ codeWriter . WriteLine ( $ """
122
+ dataTable.Rows.Add("{ schemaCollection . Name } ", { schemaCollection . Restrictions ? . Count ?? 0 } , { schemaCollection . IdentifierPartCount } );
123
+ """ ) ;
109
124
}
110
125
}
111
126
else if ( schema . Name == "Restrictions" )
@@ -117,82 +132,95 @@ public async ValueTask<DataTable> GetSchemaAsync(IOBehavior ioBehavior, string c
117
132
for ( var i = 0 ; i < schemaCollection . Restrictions . Count ; i ++ )
118
133
{
119
134
var restriction = schemaCollection . Restrictions [ i ] ;
120
- codeWriter . WriteLine ( $@ " dataTable.Rows.Add(""{ schemaCollection . Name } "", ""{ restriction . Name } "", ""{ restriction . Default } "", { i + 1 } );") ;
135
+ codeWriter . WriteLine ( $ """
136
+ dataTable.Rows.Add("{ schemaCollection . Name } ", "{ restriction . Name } ", "{ restriction . Default } ", { i + 1 } );
137
+ """ ) ;
121
138
}
122
139
}
123
140
}
124
141
}
125
142
else
126
143
{
127
- codeWriter . Write ( @$ " { schema . Custom } (dataTable);
128
- " ) ;
144
+ codeWriter . WriteLine ( $ """
145
+ { schema . Custom } (dataTable);
146
+ """ ) ;
129
147
}
130
148
131
149
if ( ! isAsync )
132
150
{
133
- codeWriter . Write ( @"
134
- return Task.CompletedTask;" ) ;
135
- }
151
+ codeWriter . Write ( """
136
152
137
- codeWriter . Write ( @"
153
+ return Task.CompletedTask;
154
+ """ ) ;
138
155
}
139
156
140
- " ) ;
157
+ codeWriter . WriteLine ( """
158
+
159
+ }
160
+
161
+ """ ) ;
141
162
}
142
163
143
- codeWriter . Write ( @"}
144
- " ) ;
164
+ codeWriter . WriteLine ( """
165
+ }
166
+ """ ) ;
145
167
146
168
using var docWriter = new StreamWriter ( @"..\..\..\..\..\docs\content\overview\schema-collections.md" ) ;
147
- docWriter . Write ( $@ "---
148
- date: 2021-04-24
149
- lastmod: { DateTime . UtcNow . ToString ( "yyyy-MM-dd" ) }
150
- menu:
151
- main:
152
- parent: getting started
153
- title: Schema Collections
154
- customtitle: ""Supported Schema Collections""
155
- weight: 80
156
- ---
169
+ docWriter . Write ( $ """
170
+ ---
171
+ date: 2021-04-24
172
+ lastmod: { DateTime . UtcNow . ToString ( "yyyy-MM-dd" ) }
173
+ menu:
174
+ main:
175
+ parent: getting started
176
+ title: Schema Collections
177
+ customtitle: ""Supported Schema Collections""
178
+ weight: 80
179
+ ---
157
180
158
- # Supported Schema Collections
181
+ # Supported Schema Collections
159
182
160
- `DbConnection.GetSchema` retrieves schema information about the database that is currently connected. For background, see MSDN on [GetSchema and Schema Collections](https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/getschema-and-schema-collections) and [Common Schema Collections](https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/common-schema-collections).
183
+ `DbConnection.GetSchema` retrieves schema information about the database that is currently connected. For background, see MSDN on [GetSchema and Schema Collections](https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/getschema-and-schema-collections) and [Common Schema Collections](https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/common-schema-collections).
161
184
162
- `MySqlConnection.GetSchema` supports the following schemas:
185
+ `MySqlConnection.GetSchema` supports the following schemas:
163
186
164
- " ) ;
187
+
188
+ """ ) ;
165
189
foreach ( var schema in schemaCollections )
166
190
docWriter . Write ( $@ "* `{ schema . Name } `{ ( schema . Description is not null ? "—[" + schema . Description + "](../schema/" + schema . Name . ToLowerInvariant ( ) + "/)" : "" ) }
167
191
" ) ;
168
192
169
193
foreach ( var schema in schemaCollections . Where ( x => x . Description is not null ) )
170
194
{
171
195
using var schemaDocWriter = new StreamWriter ( $@ "..\..\..\..\..\docs\content\overview\schema\{ schema . Name . ToLowerInvariant ( ) } .md") ;
172
- schemaDocWriter . Write ( $@ "---
173
- date: 2022-07-10
174
- lastmod: { DateTime . UtcNow . ToString ( "yyyy-MM-dd" ) }
175
- title: { schema . Name } Schema
176
- ---
196
+ schemaDocWriter . Write ( $ """
197
+ ---
198
+ date: 2022-07-10
199
+ lastmod: { DateTime . UtcNow . ToString ( "yyyy-MM-dd" ) }
200
+ title: { schema . Name } Schema
201
+ ---
177
202
178
- # { schema . Name } Schema
203
+ # { schema . Name } Schema
179
204
180
- The `{ schema . Name } ` schema provides { schema . Description } .
205
+ The `{ schema . Name } ` schema provides { schema . Description } .
181
206
182
- Column Name | Data Type | Description
183
- --- | --- | ---
184
- " ) ;
207
+ Column Name | Data Type | Description
208
+ --- | --- | ---
209
+
210
+ """ ) ;
185
211
foreach ( var column in schema . Columns )
186
212
schemaDocWriter . WriteLine ( $@ "{ column . Name } | { column . Type } | { column . Description } ") ;
187
213
schemaDocWriter . WriteLine ( ) ;
188
214
189
215
if ( schema . Restrictions is { Count : > 0 } )
190
216
{
191
- schemaDocWriter . Write ( @"The following restrictions are supported:
217
+ schemaDocWriter . Write ( """
218
+ The following restrictions are supported:
192
219
193
- Restriction Name | Restriction Default | Restriction Number
194
- --- | --- | --:
195
- " ) ;
220
+ Restriction Name | Restriction Default | Restriction Number
221
+ --- | --- | --:
222
+
223
+ """ ) ;
196
224
for ( var i = 0 ; i < schema . Restrictions . Count ; i ++ )
197
225
schemaDocWriter . WriteLine ( $@ "{ schema . Restrictions [ i ] . Name } | { schema . Restrictions [ i ] . Default } | { i + 1 } ") ;
198
226
schemaDocWriter . WriteLine ( ) ;
0 commit comments