Skip to content

Commit a4978f2

Browse files
committed
Reduce variables
1 parent fcbf2d9 commit a4978f2

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

nuget/Sqlite_net.SourceGenerator/SQLiteFastColumnSetterGenerator.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,12 @@ static void Execute(
377377
sb.AppendLine($" \"{property.ColumnName}\",");
378378
sb.AppendLine($" (obj, stmt, index) => ");
379379
sb.AppendLine($" {{");
380-
sb.AppendLine($" var typedObj = ({fullTypeName})obj;");
381380
sb.AppendLine($" var colType = SQLite3.ColumnType(stmt, index);");
382381
sb.AppendLine($" if (colType != SQLite3.ColType.Null)");
383382
sb.AppendLine($" {{");
384383

385384
// Generate appropriate setter based on property type
386-
GeneratePropertySetter(sb, property);
385+
GeneratePropertySetter($"(({fullTypeName})obj)",sb, property);
387386

388387
sb.AppendLine($" }}");
389388
sb.AppendLine($" }});");
@@ -409,7 +408,7 @@ static void Execute(
409408
}
410409

411410

412-
static void GeneratePropertySetter(StringBuilder sb, PropertyInfo property)
411+
static void GeneratePropertySetter(string typedObject, StringBuilder sb, PropertyInfo property)
413412
{
414413
var propertyType = property.TypeName;
415414

@@ -423,76 +422,76 @@ static void GeneratePropertySetter(StringBuilder sb, PropertyInfo property)
423422
case "string":
424423
case "String":
425424
case "System.String":
426-
sb.AppendLine($" typedObj.{property.PropertyName} = SQLite3.ColumnString(stmt, index);");
425+
sb.AppendLine($" {typedObject}.{property.PropertyName} = SQLite3.ColumnString(stmt, index);");
427426
break;
428427

429428
case "byte":
430429
case "Byte":
431430
case "System.Byte":
432-
sb.AppendLine ($" typedObj.{property.PropertyName} = (byte)SQLite3.ColumnInt(stmt, index);");
431+
sb.AppendLine($" {typedObject}.{property.PropertyName} = (byte)SQLite3.ColumnInt(stmt, index);");
433432
break;
434433

435434
case "short":
436435
case "Int16":
437436
case "System.Int16":
438-
sb.AppendLine ($" typedObj.{property.PropertyName} = (short)SQLite3.ColumnInt(stmt, index);");
437+
sb.AppendLine($" {typedObject}.{property.PropertyName} = (short)SQLite3.ColumnInt(stmt, index);");
439438
break;
440439

441440

442441
case "int":
443442
case "Int32":
444443
case "System.Int32":
445-
sb.AppendLine($" typedObj.{property.PropertyName} = SQLite3.ColumnInt(stmt, index);");
444+
sb.AppendLine($" {typedObject}.{property.PropertyName} = SQLite3.ColumnInt(stmt, index);");
446445
break;
447446

448447
case "long":
449448
case "Int64":
450449
case "System.Int64":
451-
sb.AppendLine($" typedObj.{property.PropertyName} = SQLite3.ColumnInt64(stmt, index);");
450+
sb.AppendLine($" {typedObject}.{property.PropertyName} = SQLite3.ColumnInt64(stmt, index);");
452451
break;
453452

454453
case "double":
455454
case "Double":
456455
case "System.Double":
457-
sb.AppendLine($" typedObj.{property.PropertyName} = SQLite3.ColumnDouble(stmt, index);");
456+
sb.AppendLine($" {typedObject}.{property.PropertyName} = SQLite3.ColumnDouble(stmt, index);");
458457
break;
459458

460459
case "decimal":
461460
case "Decimal":
462461
case "System.Decimal":
463-
sb.AppendLine ($" typedObj.{property.PropertyName} = System.Convert.ToDecimal(SQLite3.ColumnDouble(stmt, index));");
462+
sb.AppendLine($" {typedObject}.{property.PropertyName} = System.Convert.ToDecimal(SQLite3.ColumnDouble(stmt, index));");
464463
break;
465464

466465
case "float":
467466
case "Single":
468467
case "System.Single":
469-
sb.AppendLine($" typedObj.{property.PropertyName} = (float)SQLite3.ColumnDouble(stmt, index);");
468+
sb.AppendLine($" {typedObject}.{property.PropertyName} = (float)SQLite3.ColumnDouble(stmt, index);");
470469
break;
471470

472471
case "bool":
473472
case "Boolean":
474473
case "System.Boolean":
475-
sb.AppendLine($" typedObj.{property.PropertyName} = SQLite3.ColumnInt(stmt, index) == 1;");
474+
sb.AppendLine($" {typedObject}.{property.PropertyName} = SQLite3.ColumnInt(stmt, index) == 1;");
476475
break;
477476

478477
case "DateTime":
479478
case "System.DateTime":
480-
sb.AppendLine($" typedObj.{property.PropertyName} = new DateTime(SQLite3.ColumnInt64(stmt, index));");
479+
sb.AppendLine($" {typedObject}.{property.PropertyName} = new DateTime(SQLite3.ColumnInt64(stmt, index));");
481480
break;
482481

483482
case "TimeSpan":
484483
case "System.TimeSpan":
485-
sb.AppendLine ($" typedObj.{property.PropertyName} = new TimeSpan(SQLite3.ColumnInt64(stmt, index));");
484+
sb.AppendLine($" {typedObject}.{property.PropertyName} = new TimeSpan(SQLite3.ColumnInt64(stmt, index));");
486485
break;
487486

488487
case "Guid":
489488
case "System.Guid":
490489
sb.AppendLine($" var text = SQLite3.ColumnString(stmt, index);");
491-
sb.AppendLine($" typedObj.{property.PropertyName} = new Guid(text);");
490+
sb.AppendLine($" {typedObject}.{property.PropertyName} = new Guid(text);");
492491
break;
493492

494493
case "byte[]":
495-
sb.AppendLine($" typedObj.{property.PropertyName} = SQLite3.ColumnByteArray(stmt, index);");
494+
sb.AppendLine($" {typedObject}.{property.PropertyName} = SQLite3.ColumnByteArray(stmt, index);");
496495
break;
497496

498497
default:
@@ -503,12 +502,12 @@ static void GeneratePropertySetter(StringBuilder sb, PropertyInfo property)
503502
sb.AppendLine ($" var value = SQLite3.ColumnString(stmt, index);");
504503
sb.AppendLine ($" if (value != null)");
505504
sb.AppendLine ($" {{");
506-
sb.AppendLine ($" typedObj.{property.PropertyName} = ({propertyType})Enum.Parse(typeof({propertyType}), value, ignoreCase: true);");
505+
sb.AppendLine ($" {typedObject}.{property.PropertyName} = ({propertyType})Enum.Parse(typeof({propertyType}), value, ignoreCase: true);");
507506
sb.AppendLine ($" }}");
508507
}
509508
else {
510509
sb.AppendLine ($" var value = SQLite3.ColumnInt(stmt, index);");
511-
sb.AppendLine ($" typedObj.{property.PropertyName} = ({propertyType})value;");
510+
sb.AppendLine ($" {typedObject}.{property.PropertyName} = ({propertyType})value;");
512511
}
513512
}
514513
else {
@@ -517,7 +516,7 @@ static void GeneratePropertySetter(StringBuilder sb, PropertyInfo property)
517516
sb.AppendLine ($" var value = SQLite3.ColumnString(stmt, index);");
518517
sb.AppendLine ($" if (value != null)");
519518
sb.AppendLine ($" {{");
520-
sb.AppendLine ($" typedObj.{property.PropertyName} = ({propertyType})Convert.ChangeType(value, typeof({propertyType}));");
519+
sb.AppendLine ($" {typedObject}.{property.PropertyName} = ({propertyType})Convert.ChangeType(value, typeof({propertyType}));");
521520
sb.AppendLine ($" }}");
522521
}
523522

tests/SQLite.Tests/SQLite.Tests.csproj

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

1717
<!-- SourceGenerator -->

0 commit comments

Comments
 (0)