14
14
using Initialisations ;
15
15
using NetStandardPolyfills ;
16
16
using static System . Convert ;
17
+ using static System . Environment ;
17
18
using static System . Globalization . CultureInfo ;
18
19
#if NET35
19
20
using static Microsoft . Scripting . Ast . ExpressionType ;
@@ -160,12 +161,14 @@ private static bool TryTranslateFromTypeCode(
160
161
return true ;
161
162
162
163
case NetStandardTypeCode . String :
163
- var stringValue = ( ( string ) constant . Value )
164
- . Replace ( @"\" , @"\\" )
165
- . Replace ( "\0 " , @"\0" )
166
- . Replace ( @"""" , @"\""" ) ;
167
-
164
+ var stringValue = GetStringConstant ( constant , out var isVerbatim ) ;
168
165
stringValue = "\" " + stringValue + "\" " ;
166
+
167
+ if ( isVerbatim )
168
+ {
169
+ stringValue = "@" + stringValue ;
170
+ }
171
+
169
172
translation = FixedValueTranslation ( stringValue , typeof ( string ) , Text , context ) ;
170
173
return true ;
171
174
}
@@ -213,6 +216,13 @@ private static ITranslation GetDoubleTranslation(
213
216
return FixedValueTranslation ( stringValue + "d" , constant . Type , Numeric , context ) ;
214
217
}
215
218
219
+ private static ITranslation GetLongTranslation (
220
+ ConstantExpression constant ,
221
+ ITranslationContext context )
222
+ {
223
+ return FixedValueTranslation ( ( long ) constant . Value + "L" , constant . Type , Numeric , context ) ;
224
+ }
225
+
216
226
private static ITranslation GetFloatTranslation (
217
227
ConstantExpression constant ,
218
228
ITranslationContext context )
@@ -226,11 +236,17 @@ private static ITranslation GetFloatTranslation(
226
236
return FixedValueTranslation ( stringValue + "f" , constant . Type , Numeric , context ) ;
227
237
}
228
238
229
- private static ITranslation GetLongTranslation (
239
+ private static string GetStringConstant (
230
240
ConstantExpression constant ,
231
- ITranslationContext context )
241
+ out bool isVerbatim )
232
242
{
233
- return FixedValueTranslation ( ( long ) constant . Value + "L" , constant . Type , Numeric , context ) ;
243
+ var stringValue = ( string ) constant . Value ;
244
+ isVerbatim = stringValue . Contains ( NewLine ) ;
245
+
246
+ return stringValue
247
+ . Replace ( @"\" , @"\\" )
248
+ . Replace ( "\0 " , @"\0" )
249
+ . Replace ( @"""" , isVerbatim ? @"""""" : @"\""" ) ;
234
250
}
235
251
236
252
private static bool TryGetTypeTranslation (
0 commit comments