Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 6ffe7b8

Browse files
fix #106: Source code file reference cannot be extracted from non-English stacktrace
by using ´Environment.GetResourceString´ through reflection
1 parent 00d2fd1 commit 6ffe7b8

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/OutputTextLineParser.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static FileLineReference GetFileLineReference(string lineText)
8585
/// Extracts source code file reference from NUnit output. (stacktrace format)
8686
/// </summary>
8787
/// <param name="lineText">The text line to parse.</param>
88-
/// <param name="multiline">The <paramref name="line"/> text is multilined.</param>
88+
/// <param name="multiline">The <paramref name="lineText"/> text is multilined.</param>
8989
/// <returns>A <see cref="FileLineReference"/> if the line of text contains a
9090
/// file reference otherwise <see langword="null"/></returns>
9191
public static FileLineReference GetNUnitOutputFileLineReference(string lineText, bool multiline)
@@ -95,7 +95,7 @@ public static FileLineReference GetNUnitOutputFileLineReference(string lineText,
9595
FileLineReference result = null;
9696

9797
if (lineText != null) {
98-
Match match = Regex.Match(lineText, @"\b(\w:[/\\].*?):line\s(\d+)?\r?$", regexOptions);
98+
Match match = Regex.Match(lineText, GetStackFrameRegex(), regexOptions);
9999
while (match.Success) {
100100
try {
101101
int line = Convert.ToInt32(match.Groups[2].Value);
@@ -110,6 +110,21 @@ public static FileLineReference GetNUnitOutputFileLineReference(string lineText,
110110

111111
return result;
112112
}
113+
114+
static readonly System.Reflection.MethodInfo GetResourceString = typeof(Environment)
115+
.GetMethod("GetResourceString", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic,
116+
null, new[] { typeof(string) }, null);
117+
118+
static string GetStackFrameRegex()
119+
{
120+
string line = "in {0}:line {1}";
121+
122+
if (GetResourceString != null) {
123+
line = (string)GetResourceString.Invoke(null, new[] { "StackTrace_InFileLineNumber" });
124+
}
125+
126+
return line.Replace("{0}", @"(\w:[/\\].*?)").Replace("{1}", @"(\d+)");
127+
}
113128

114129
/// <summary>
115130
/// Extracts source code file reference from the c++ or VB.Net compiler output.

0 commit comments

Comments
 (0)