Skip to content

Commit 2aaeff7

Browse files
committed
Use raw strings.
Signed-off-by: Bradley Grainger <[email protected]>
1 parent 7a05d8e commit 2aaeff7

File tree

1 file changed

+116
-88
lines changed

1 file changed

+116
-88
lines changed

tools/SchemaCollectionGenerator/SchemaCollectionGenerator.cs

Lines changed: 116 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -13,99 +13,114 @@
1313
var schemaCollections = deserializer.Deserialize<List<Schema>>(reader);
1414

1515
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;
2021
21-
namespace MySqlConnector.Core;
22+
namespace MySqlConnector.Core;
2223
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
2625
{
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));
2930
30-
var dataTable = new DataTable(collectionName);
31-
");
32-
string elseIf = "if";
31+
var dataTable = new DataTable(collectionName);
32+
""");
33+
var elseIf = "if";
3334
foreach (var schema in schemaCollections)
3435
{
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+
""");
3840
elseIf = "else if";
3941
}
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));
4245
43-
return dataTable;
44-
}
46+
return dataTable;
47+
}
4548
46-
");
49+
""");
4750

4851
foreach (var schema in schemaCollections)
4952
{
5053
var isAsync = schema.Table is not null;
5154
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+
""");
5559
if (!supportsRestrictions)
5660
{
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+
""");
6065
}
6166
else
6267
{
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+
""");
6672
}
6773

68-
codeWriter.Write($@"
69-
dataTable.Columns.AddRange(new DataColumn[]
70-
{{
71-
");
74+
codeWriter.WriteLine("""
75+
76+
dataTable.Columns.AddRange(new DataColumn[]
77+
{
78+
""");
7279
foreach (var column in schema.Columns)
7380
{
74-
codeWriter.Write($@" new(""{column.Name}"", typeof({column.Type})),
75-
");
81+
codeWriter.WriteLine($"""
82+
new("{column.Name}", typeof({column.Type})),
83+
""");
7684
}
77-
codeWriter.Write($@" }});
85+
codeWriter.WriteLine("""
86+
});
7887
79-
");
88+
""");
8089
if (schema.Table is string table)
8190
{
8291
if (supportsRestrictions)
8392
{
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+
""");
8898
for (var i = 0; i < schema.Restrictions!.Count; i++)
8999
{
90100
if (!schema.Columns.Any(x => x.Name == schema.Restrictions[i].Default))
91101
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+
""");
95106
}
96-
codeWriter.Write(@" }
107+
codeWriter.WriteLine("""
108+
}
97109
98-
");
110+
""");
99111
}
100112

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+
""");
102116
}
103117
else if (schema.Name == "MetaDataCollections")
104118
{
105119
foreach (var schemaCollection in schemaCollections)
106120
{
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+
""");
109124
}
110125
}
111126
else if (schema.Name == "Restrictions")
@@ -117,82 +132,95 @@ public async ValueTask<DataTable> GetSchemaAsync(IOBehavior ioBehavior, string c
117132
for (var i = 0; i < schemaCollection.Restrictions.Count; i++)
118133
{
119134
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+
""");
121138
}
122139
}
123140
}
124141
}
125142
else
126143
{
127-
codeWriter.Write(@$" {schema.Custom}(dataTable);
128-
");
144+
codeWriter.WriteLine($"""
145+
{schema.Custom}(dataTable);
146+
""");
129147
}
130148

131149
if (!isAsync)
132150
{
133-
codeWriter.Write(@"
134-
return Task.CompletedTask;");
135-
}
151+
codeWriter.Write("""
136152
137-
codeWriter.Write(@"
153+
return Task.CompletedTask;
154+
""");
138155
}
139156

140-
");
157+
codeWriter.WriteLine("""
158+
159+
}
160+
161+
""");
141162
}
142163

143-
codeWriter.Write(@"}
144-
");
164+
codeWriter.WriteLine("""
165+
}
166+
""");
145167

146168
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+
---
157180
158-
# Supported Schema Collections
181+
# Supported Schema Collections
159182
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).
161184
162-
`MySqlConnection.GetSchema` supports the following schemas:
185+
`MySqlConnection.GetSchema` supports the following schemas:
163186
164-
");
187+
188+
""");
165189
foreach (var schema in schemaCollections)
166190
docWriter.Write($@"* `{schema.Name}`{(schema.Description is not null ? "—[" + schema.Description + "](../schema/" + schema.Name.ToLowerInvariant() + "/)" : "")}
167191
");
168192

169193
foreach (var schema in schemaCollections.Where(x => x.Description is not null))
170194
{
171195
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+
---
177202
178-
# {schema.Name} Schema
203+
# {schema.Name} Schema
179204
180-
The `{schema.Name}` schema provides {schema.Description}.
205+
The `{schema.Name}` schema provides {schema.Description}.
181206
182-
Column Name | Data Type | Description
183-
--- | --- | ---
184-
");
207+
Column Name | Data Type | Description
208+
--- | --- | ---
209+
210+
""");
185211
foreach (var column in schema.Columns)
186212
schemaDocWriter.WriteLine($@"{column.Name} | {column.Type} | {column.Description}");
187213
schemaDocWriter.WriteLine();
188214

189215
if (schema.Restrictions is { Count: > 0 })
190216
{
191-
schemaDocWriter.Write(@"The following restrictions are supported:
217+
schemaDocWriter.Write("""
218+
The following restrictions are supported:
192219
193-
Restriction Name | Restriction Default | Restriction Number
194-
--- | --- | --:
195-
");
220+
Restriction Name | Restriction Default | Restriction Number
221+
--- | --- | --:
222+
223+
""");
196224
for (var i = 0; i < schema.Restrictions.Count; i++)
197225
schemaDocWriter.WriteLine($@"{schema.Restrictions[i].Name} | {schema.Restrictions[i].Default} | {i + 1}");
198226
schemaDocWriter.WriteLine();

0 commit comments

Comments
 (0)