Skip to content

Commit 8d6bcca

Browse files
committed
[dotnet] Move initialization of error codes to static ctor
1 parent 3338c08 commit 8d6bcca

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

dotnet/src/webdriver/WebDriverError.cs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -183,33 +183,9 @@ internal static class WebDriverError
183183
/// </summary>
184184
public const string UnsupportedOperation = "unsupported operation";
185185

186-
private static Dictionary<string, WebDriverResult> resultMap;
187-
private static object lockObject = new object();
186+
private static readonly Dictionary<string, WebDriverResult> resultMap;
188187

189-
/// <summary>
190-
/// Converts a string error to a <see cref="WebDriverResult"/> value.
191-
/// </summary>
192-
/// <param name="error">The error string to convert.</param>
193-
/// <returns>The converted <see cref="WebDriverResult"/> value.</returns>
194-
public static WebDriverResult ResultFromError(string error)
195-
{
196-
lock (lockObject)
197-
{
198-
if (resultMap == null)
199-
{
200-
InitializeResultMap();
201-
}
202-
}
203-
204-
if (!resultMap.ContainsKey(error))
205-
{
206-
error = UnsupportedOperation;
207-
}
208-
209-
return resultMap[error];
210-
}
211-
212-
private static void InitializeResultMap()
188+
static WebDriverError()
213189
{
214190
resultMap = new Dictionary<string, WebDriverResult>();
215191
resultMap[ElementClickIntercepted] = WebDriverResult.ElementClickIntercepted;
@@ -244,5 +220,20 @@ private static void InitializeResultMap()
244220
resultMap[UnknownMethod] = WebDriverResult.UnknownCommand;
245221
resultMap[UnsupportedOperation] = WebDriverResult.UnhandledError;
246222
}
223+
224+
/// <summary>
225+
/// Converts a string error to a <see cref="WebDriverResult"/> value.
226+
/// </summary>
227+
/// <param name="error">The error string to convert.</param>
228+
/// <returns>The converted <see cref="WebDriverResult"/> value.</returns>
229+
public static WebDriverResult ResultFromError(string error)
230+
{
231+
if (!resultMap.ContainsKey(error))
232+
{
233+
error = UnsupportedOperation;
234+
}
235+
236+
return resultMap[error];
237+
}
247238
}
248239
}

0 commit comments

Comments
 (0)