Skip to content

Commit 8478d15

Browse files
committed
InitPerClass
1 parent c43bec5 commit 8478d15

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

nuget/Sqlite_net.SourceGenerator/SQLiteFastColumnSetterGenerator.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,32 +360,45 @@ static void Execute(
360360
sb.AppendLine("#endif");
361361
sb.AppendLine(" public static void Init()");
362362
sb.AppendLine(" {");
363-
sb.AppendLine (" if (initialized)");
364-
sb.AppendLine (" return;");
365-
sb.AppendLine (" initialized = true;");
363+
sb.AppendLine(" if (initialized)");
364+
sb.AppendLine(" return;");
365+
sb.AppendLine(" initialized = true;");
366+
367+
foreach (var classInfo in classes) {
368+
var fullTypeName = FullTypeName (classInfo);
369+
var initName = "Init" + fullTypeName.Replace (".", "_");
370+
sb.AppendLine($" {initName}();");
371+
}
366372

367-
foreach (var classInfo in classes)
368-
{
369-
foreach (var property in classInfo.Properties)
370-
{
371-
var fullTypeName = string.IsNullOrEmpty(classInfo.Namespace)
372-
? classInfo.ClassName
373-
: $"{classInfo.Namespace}.{classInfo.ClassName}";
373+
sb.AppendLine (" }");
374374

375+
foreach (var classInfo in classes) {
376+
var fullTypeName = FullTypeName (classInfo);
377+
var initName = "Init" + fullTypeName.Replace (".", "_");
378+
sb.AppendLine($" public static void {initName}()");
379+
sb.AppendLine(" {");
380+
foreach (var property in classInfo.Properties) {
375381
sb.AppendLine($" SQLiteConnection.RegisterFastColumnSetter(");
376382
sb.AppendLine($" typeof({fullTypeName}),");
377383
sb.AppendLine($" \"{property.ColumnName}\",");
378384
sb.Append($" (obj, stmt, index) => ");
379385
GeneratePropertySetter ($"(({fullTypeName})obj)", sb, property);
380386
}
381-
}
387+
sb.AppendLine (" }");
388+
}
382389

383-
sb.AppendLine(" }");
384390
sb.AppendLine(" }");
385391
sb.AppendLine("}");
386392

387393
context.AddSource("SQLiteInitializer.g.cs", SourceText.From(sb.ToString(), Encoding.UTF8));
388394
}
395+
396+
static string FullTypeName (ClassInfo classInfo)
397+
{
398+
return string.IsNullOrEmpty (classInfo.Namespace)
399+
? classInfo.ClassName
400+
: $"{classInfo.Namespace}.{classInfo.ClassName}";
401+
}
389402

390403
static string? GetRootNamespace(AnalyzerConfigOptionsProvider configOptionsProvider, Compilation compilation)
391404
{

tests/SQLite.Tests/SQLite.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<ItemGroup>
1111
<PackageReference Include="AltCover" Version="8.7.3" />
1212
<PackageReference Include="NUnit" Version="3.12.0" />
13-
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
13+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
1515
</ItemGroup>
1616

0 commit comments

Comments
 (0)