Skip to content

Commit 9a78549

Browse files
- Issue #213: Error message uses a non-Windows \n instead of e.g. Environment.NewLine
1 parent 4ddf2c7 commit 9a78549

16 files changed

+120
-89
lines changed

Source/CSScriptLibrary/AsmHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,11 +1492,11 @@ public object Invoke(object obj, string methodName, params object[] list)
14921492
if (list.Any(x => x == null))
14931493
throw new Exception("At least one of the invoke parameters is null. This makes impossible to " +
14941494
"match method signature by the parameter type. Consider using alternative invoking " +
1495-
"mechanisms like:\n" +
1496-
" AsmHelper.GetMethod()\n" +
1497-
" AsmHelper.GetStaticMethod()\n" +
1498-
" Assembly.GetStaticMethod()\n" +
1499-
" using type 'dynamic'\n" +
1495+
"mechanisms like:" + Environment.NewLine +
1496+
" AsmHelper.GetMethod()" + Environment.NewLine +
1497+
" AsmHelper.GetStaticMethod()" + Environment.NewLine +
1498+
" Assembly.GetStaticMethod()" + Environment.NewLine +
1499+
" using type 'dynamic'" + Environment.NewLine +
15001500
" using interfaces");
15011501

15021502
MethodSignature methodID = new MethodSignature(methodName, list);
@@ -1677,7 +1677,7 @@ static public Type FindFirstScriptUserType(Assembly asm, string typeName)
16771677

16781678
if (!isMonoInternalType && !isRoslynInternalType && !isRoslynInternalType2)
16791679
{
1680-
if (typeName == null || type.Name == typeName || type.Name == "DynamicClass" || isLikelyUserType)
1680+
if (typeName == null || type.Name == typeName || type.Name == "DynamicClass" || isLikelyUserType)
16811681
return type;
16821682
}
16831683
}

Source/CSScriptLibrary/CSScriptLib.Eval.Mono.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ Assembly GetCompiledAssembly(int id)
900900

901901
string GetConnectionPointClassDeclaration(int id)
902902
{
903-
return "\n public struct CSS_ConnectionPoint_" + id + " {}";
903+
return Environment.NewLine + " public struct CSS_ConnectionPoint_" + id + " {}";
904904
}
905905

906906
string GetConnectionPointGetTypeExpression(int id)

Source/CSScriptLibrary/CSScriptLib.cs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,8 +1531,8 @@ static internal string WrapMethodToAutoClass(string methodCode, bool injectStati
15311531
#endif
15321532
{
15331533
StringBuilder code = new StringBuilder(4096);
1534-
code.Append("//Auto-generated file\r\n"); //cannot use AppendLine as it is not available in StringBuilder v1.1
1535-
code.Append("using System;\r\n");
1534+
code.AppendLine("//Auto-generated file");
1535+
code.AppendLine("using System;");
15361536

15371537
bool headerProcessed = false;
15381538

@@ -1550,38 +1550,35 @@ static internal string WrapMethodToAutoClass(string methodCode, bool injectStati
15501550

15511551
if (injectNamespace)
15521552
{
1553-
code.Append("namespace Scripting\r\n");
1554-
code.Append("{\r\n");
1553+
code.AppendLine("namespace Scripting");
1554+
code.AppendLine("{");
15551555
}
15561556

15571557
if (inheritFrom != null)
1558-
code.Append(" public class " + ClasslessScriptTypeName + " : " + inheritFrom + "\r\n");
1558+
code.AppendLine(" public class " + ClasslessScriptTypeName + " : " + inheritFrom);
15591559
else
1560-
code.Append(" public class " + ClasslessScriptTypeName + "\r\n");
1560+
code.AppendLine(" public class " + ClasslessScriptTypeName);
15611561

1562-
code.Append(" {\r\n");
1562+
code.AppendLine(" {");
15631563
string[] tokens = line.Split("\t ".ToCharArray(), 3, StringSplitOptions.RemoveEmptyEntries);
15641564

15651565
if (injectStatic)
15661566
{
1567-
//if (tokens[0] != "static" && tokens[1] != "static" && tokens[2] != "static") //unsafe public static
15681567
if (!tokens.Contains("static")) //unsafe public static
1569-
code.Append(" static\r\n");
1568+
code.AppendLine(" static");
15701569
}
15711570

1572-
//if (tokens[0] != "public" && tokens[1] != "public" && tokens[2] != "public")
15731571
if (!tokens.Contains("public"))
1574-
code.Append(" public\r\n");
1572+
code.AppendLine(" public");
15751573
}
15761574
}
15771575

1578-
code.Append(line);
1579-
code.Append("\r\n");
1576+
code.AppendLine(line);
15801577
}
15811578

1582-
code.Append(" }\r\n");
1579+
code.AppendLine(" }");
15831580
if (injectNamespace)
1584-
code.Append("}\r\n");
1581+
code.AppendLine("}");
15851582

15861583
return code.ToString();
15871584
}
@@ -2449,19 +2446,19 @@ internal class AppInfo
24492446

24502447
public static string appLogo
24512448
{
2452-
get { return "C# Script execution engine. Version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + ".\nCopyright (C) 2004 Oleg Shilo.\n"; }
2449+
get { return "C# Script execution engine. Version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + "." + Environment.NewLine + "Copyright (C) 2004 Oleg Shilo." + Environment.NewLine; }
24532450
}
24542451

24552452
public static string appLogoShort
24562453
{
2457-
get { return "C# Script execution engine. Version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + ".\n"; }
2454+
get { return "C# Script execution engine. Version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + Environment.NewLine; }
24582455
}
24592456

24602457
//#pragma warning disable 414
24612458
public static string appParams = "[/nl]:";
24622459

24632460
//#pragma warning restore 414
2464-
public static string appParamsHelp = "nl - No logo mode: No banner will be shown at execution time.\n";
2461+
public static string appParamsHelp = "nl - No logo mode: No banner will be shown at execution time." + Environment.NewLine;
24652462
}
24662463

24672464
/// <summary>

Source/CSScriptLibrary/ObjectCaster.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static Type BuildProxyClass(Type interfaceType, Type sourceType, bool injectName
232232
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
233233

234234
if (sourceType.Assembly.Location() == "" || interfaceType.Assembly.Location() == "")
235-
throw new Exception("Error compiling proxy class:\nThe dependency assembly is dynamic and doesn't have an assembly " +
235+
throw new Exception("Error compiling proxy class:" + Environment.NewLine + "The dependency assembly is dynamic and doesn't have an assembly " +
236236
"file associated with it. You will need to ensure the all engaged assemblies are loaded from the file system or " +
237237
"script assemblies are compiled with CSScript.GlobalSettings.InMemoryAssembly set to `false`. Another alternative is " +
238238
"to avoid duck typing by directly inheriting the sourceType from the interfaceType.");
@@ -262,7 +262,7 @@ static Type BuildProxyClass(Type interfaceType, Type sourceType, bool injectName
262262
sb.AppendLine(error.Line + "\t" + error.ErrorNumber + "\t" + error.ErrorText);
263263
}
264264

265-
throw new Exception("Error compiling proxy class:\n" + sb.ToString());
265+
throw new Exception("Error compiling proxy class:" + Environment.NewLine + sb.ToString());
266266
}
267267

268268
return res.CompiledAssembly.GetTypes()[0];

Source/Exceptions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@
3939

4040
namespace csscript
4141
{
42+
/// <summary>
43+
/// The exception that is thrown when an incvalid CS-Script directive is encountered.
44+
/// </summary>
45+
/// <seealso cref="csscript.CompilerException" />
4246
public class InvalidDirectiveException : CompilerException
4347
{
48+
/// <summary>
49+
/// Initializes a new instance of the <see cref="InvalidDirectiveException"/> class.
50+
/// </summary>
51+
/// <param name="message">The message.</param>
4452
public InvalidDirectiveException(string message) : base(message)
4553
{
4654
}

Source/HelpProvider.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -992,19 +992,19 @@ public static string BuildVersionInfo()
992992
if (Runtime.IsWin && !corlib.Contains("mono"))
993993
dotNetVer = DotNetVersion.Get45PlusFromRegistry();
994994

995-
builder.Append(AppInfo.appLogo.TrimEnd() + " www.csscript.net (github.com/oleg-shilo/cs-script)\n");
996-
builder.Append("\n");
997-
builder.Append(" CLR: " + Environment.Version + (dotNetVer != null ? " (.NET Framework v" + dotNetVer + ")" : "") + "\n");
998-
builder.Append(" System: " + Environment.OSVersion + "\n");
999-
builder.Append(" Corlib: " + "".GetType().Assembly.Location + "\n");
995+
builder.AppendLine(AppInfo.appLogo.TrimEnd() + " www.csscript.net (github.com/oleg-shilo/cs-script)");
996+
builder.AppendLine("");
997+
builder.AppendLine(" CLR: " + Environment.Version + (dotNetVer != null ? " (.NET Framework v" + dotNetVer + ")" : ""));
998+
builder.AppendLine(" System: " + Environment.OSVersion);
999+
builder.AppendLine(" Corlib: " + "".GetType().Assembly.Location);
10001000
#if net4
1001-
builder.Append(" Architecture: " + (Environment.Is64BitProcess ? "x64" : "x86") + "\n");
1001+
builder.AppendLine(" Architecture: " + (Environment.Is64BitProcess ? "x64" : "x86"));
10021002
#endif
1003-
builder.Append(" Install dir: " + (Environment.GetEnvironmentVariable("CSSCRIPT_DIR") ?? "<not integrated>") + "\n");
1003+
builder.AppendLine(" Install dir: " + (Environment.GetEnvironmentVariable("CSSCRIPT_DIR") ?? "<not integrated>"));
10041004

10051005
var asm_path = Assembly.GetExecutingAssembly().Location;
1006-
builder.Append(" Location: " + asm_path + "\n");
1007-
builder.Append(" Config file: " + (Settings.DefaultConfigFile ?? "<none>") + "\n");
1006+
builder.AppendLine(" Location: " + asm_path);
1007+
builder.AppendLine(" Config file: " + (Settings.DefaultConfigFile ?? "<none>"));
10081008
builder.Append(" Compiler: ");
10091009
var compiler = "<default>";
10101010
if (!string.IsNullOrEmpty(asm_path))
@@ -1013,7 +1013,7 @@ public static string BuildVersionInfo()
10131013
var alt_compiler = (Settings.Load(Settings.DefaultConfigFile, false) ?? new Settings()).ExpandUseAlternativeCompiler();
10141014
if (!string.IsNullOrEmpty(alt_compiler))
10151015
{
1016-
builder.Append(alt_compiler + "\n");
1016+
builder.AppendLine(alt_compiler);
10171017
try
10181018
{
10191019
var asm = Assembly.LoadFrom(CSExecutor.LookupAltCompilerFile(alt_compiler));
@@ -1025,22 +1025,23 @@ public static string BuildVersionInfo()
10251025
var info = (Dictionary<string, string>)method.Invoke(null, new object[0]);
10261026
var maxLength = info.Keys.Max(x => x.Length);
10271027
foreach (var key in info.Keys)
1028-
builder.AppendLine(" " + key + " - \n " + info[key]);
1029-
// builder.AppendLine(" " + key.PadRight(maxLength) + " - " + info[key]);
1028+
{
1029+
builder.AppendLine(" " + key + " - ")
1030+
.AppendLine(" " + info[key]);
1031+
}
10301032
}
10311033
}
10321034
catch { }
10331035
}
10341036
else
1035-
builder.Append(compiler + "\n");
1037+
builder.AppendLine(compiler);
10361038
}
10371039
else
1038-
builder.Append(compiler + "\n");
1040+
builder.AppendLine(compiler);
10391041

1040-
builder.Append(" NuGet manager: " + NuGet.NuGetExe + "\n");
1041-
builder.Append(" NuGet cache: " + NuGet.NuGetCacheView + "\n");
1042+
builder.AppendLine(" NuGet manager: " + NuGet.NuGetExe);
1043+
builder.AppendLine(" NuGet cache: " + NuGet.NuGetCacheView);
10421044

1043-
//builder.Append(" Engine: " + Assembly.GetExecutingAssembly().Location + "\n");
10441045
return builder.ToString();
10451046
}
10461047
}

Source/NuGet.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ static public string[] Resolve(string[] packages, bool suppressDownloading, stri
330330

331331
if (abort_downloading)
332332
{
333-
Console.WriteLine("Warning: Resolving (installing) NuGet package has been aborted due to the incompatibility of the CS-Script host with the nuget stdout redirection.\n" +
334-
"Run the script from the terminal (e.g. Ctrl+F5 in ST3) at least once to resolve all missing NuGet packages.");
333+
Console.WriteLine("Warning: Resolving (installing) NuGet package has been aborted due to the incompatibility of the CS-Script host with the nuget stdout redirection.");
334+
Console.WriteLine("Run the script from the terminal (e.g. Ctrl+F5 in ST3) at least once to resolve all missing NuGet packages.");
335335
Console.WriteLine();
336336
}
337337
else
@@ -359,6 +359,7 @@ static public string[] Resolve(string[] packages, bool suppressDownloading, stri
359359
}
360360
catch (Exception e)
361361
{
362+
// the failed package willl be reported as missing reference anyway
362363
}
363364

364365
try
@@ -710,7 +711,9 @@ static void Run(string exe, string args)
710711
//http://stackoverflow.com/questions/38118548/how-to-install-nuget-from-command-line-on-linux
711712
//on Linux native "nuget" app doesn't play nice with std.out redirected
712713

713-
Console.WriteLine("NuGet shell command: \n{0} {1}\n", exe, args);
714+
Console.WriteLine("NuGet shell command: ");
715+
Console.WriteLine("{0} {1}", exe, args);
716+
Console.WriteLine();
714717

715718
if (Runtime.IsLinux)
716719
{

Source/NuGet/content/net45/Scripting.Extensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public static void Test()
3737
Console.WriteLine("---------------------------------------------");
3838
new AsyncSamples().RunAll();
3939
Thread.Sleep(2000);
40-
Console.WriteLine("\nPress 'Enter' to run uloading samples...");
40+
Console.WriteLine();
41+
Console.WriteLine("Press 'Enter' to run unloading samples...");
4142
Console.ReadLine();
4243
Console.WriteLine("---------------------------------------------");
4344
Console.WriteLine("Testing unloading API");

Source/NuGet/content/net45/Scripting.evaluator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,10 @@ public static void Profile()
309309

310310
Action runAll = () =>
311311
{
312-
Console.WriteLine("\n---------------------------------------------");
313-
Console.WriteLine("Caching enabled: " + preventCaching + "\n");
312+
Console.WriteLine();
313+
Console.WriteLine("---------------------------------------------");
314+
Console.WriteLine("Caching enabled: " + preventCaching);
315+
Console.WriteLine();
314316

315317
CSScript.EvaluatorConfig.Engine = EvaluatorEngine.Mono;
316318
run();

Source/Precompiler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ internal static Result Process(string content, string consoleEncoding)
277277

278278
var code = new StringBuilder(4096);
279279
var footer = new StringBuilder();
280-
//code.Append("//Auto-generated file" + Environment.NewLine); //cannot use AppendLine as it is not available in StringBuilder v1.1
281-
//code.Append("using System;\r\n");
282280

283281
//css_ac_end
284282
bool headerProcessed = false;

0 commit comments

Comments
 (0)