Skip to content

Commit 4e07a7c

Browse files
committed
more variable reductions
1 parent 0ae89a4 commit 4e07a7c

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

nuget/Sqlite_net.SourceGenerator/SQLiteFastColumnSetterGenerator.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -497,24 +497,16 @@ static void GeneratePropertySetter(string typedObject, StringBuilder sb, Propert
497497
// For other types, try to use a generic approach
498498
sb.AppendLine ($" // Enum setter for {propertyType}");
499499
if (property.Enum.StoreAsText) {
500-
sb.AppendLine ($" var value = SQLite3.ColumnString(stmt, index);");
501-
sb.AppendLine ($" if (value != null)");
502-
sb.AppendLine ($" {{");
503-
sb.AppendLine ($" {typedObject}.{property.PropertyName} = ({propertyType})Enum.Parse(typeof({propertyType}), value, ignoreCase: true);");
504-
sb.AppendLine ($" }}");
500+
sb.AppendLine($" {typedObject}.{property.PropertyName} = ({propertyType})Enum.Parse(typeof({propertyType}), SQLite3.ColumnString(stmt, index), ignoreCase: true);");
505501
}
506502
else {
507-
sb.AppendLine ($" {typedObject}.{property.PropertyName} = ({propertyType})SQLite3.ColumnInt(stmt, index);");
503+
sb.AppendLine($" {typedObject}.{property.PropertyName} = ({propertyType})SQLite3.ColumnInt(stmt, index);");
508504
}
509505
}
510506
else {
511507
// For other types, try to use a generic approach
512-
sb.AppendLine ($" // Generic setter for {propertyType}");
513-
sb.AppendLine ($" var value = SQLite3.ColumnString(stmt, index);");
514-
sb.AppendLine ($" if (value != null)");
515-
sb.AppendLine ($" {{");
516-
sb.AppendLine ($" {typedObject}.{property.PropertyName} = ({propertyType})Convert.ChangeType(value, typeof({propertyType}));");
517-
sb.AppendLine ($" }}");
508+
sb.AppendLine($" // Generic setter for {propertyType}");
509+
sb.AppendLine($" {typedObject}.{property.PropertyName} = ({propertyType})Convert.ChangeType(SQLite3.ColumnString(stmt, index), typeof({propertyType}));");
518510
}
519511

520512
break;

0 commit comments

Comments
 (0)