Code generator improvements (#940)

* Fix quotation marks escaping in multiline string

* Add support for JsonPartialMatcher and JsonPartialWildcardMatcher in mapping code generator
This commit is contained in:
Cezary Piątek
2023-05-25 20:59:13 +02:00
committed by GitHub
parent 7c3a0c815d
commit e5cc6f570c
4 changed files with 68 additions and 7 deletions

View File

@@ -129,15 +129,25 @@ internal static class CSharpFormatter
};
}
public static string ToCSharpBooleanLiteral(bool value) => value ? "true" : "false";
public static string ToCSharpStringLiteral(string? value)
{
var escapedValue = value?.Replace("\"", "\\\"") ?? string.Empty;
if (escapedValue.Contains("\n"))
if (string.IsNullOrEmpty(value))
{
return $"@\"{escapedValue}\"";
return "\"\"";
}
return $"\"{escapedValue}\"";
if (value.Contains("\n"))
{
var escapedValue = value?.Replace("\"", "\"\"") ?? string.Empty;
return $"@\"{escapedValue}\"";
}
else
{
var escapedValue = value?.Replace("\"", "\\\"") ?? string.Empty;
return $"\"{escapedValue}\"";
}
}
public static string FormatPropertyName(string propertyName)