Skip to content

Commit

Permalink
Use StringBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd committed Oct 6, 2023
1 parent b017dd5 commit efb1445
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/EFCore.Design/Design/Internal/CSharpHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections;
using System.Globalization;
using System.Numerics;
Expand Down Expand Up @@ -329,15 +330,17 @@ public virtual string Namespace(params string[] name)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual string Literal(string? value)
// do not use @"" syntax as in Migrations this can get indented at a newline and so add spaces to the literal
// do not output @"" syntax as in Migrations this can get indented at a newline and so add spaces to the literal
=> value is not null
? "\"" +
value.Replace(@"\", @"\\")
.Replace("\"", "\\\"")
.Replace("\0", @"\0")
.Replace("\n", @"\n")
.Replace("\r", @"\r") +
"\""
? new StringBuilder(value)
.Replace("\\", @"\\")
.Replace("\0", @"\0")
.Replace("\n", @"\n")
.Replace("\r", @"\r")
.Replace("\"", "\\\"")
.Insert(0, "\"")
.Append("\"")
.ToString()
: "null";

/// <summary>
Expand Down Expand Up @@ -368,11 +371,11 @@ public virtual string Literal(char value)
=> "\'"
+ value switch
{
'\'' => @"\'",
'\\' => @"\\",
'\0' => @"\0",
'\n' => @"\n",
'\r' => @"\r",
'\'' => @"\'",
_ => value.ToString()
}
+ "\'";
Expand Down

0 comments on commit efb1445

Please sign in to comment.