Skip to content

Commit 1164350

Browse files
committed
error to string
1 parent 1405dd2 commit 1164350

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/S7CommPlusDriver/Net/Error.cs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
namespace S7CommPlusDriver.Net
5+
{
6+
public class Error
7+
{
8+
private static readonly Dictionary<int, string> errorsDictionary;
9+
10+
static Error()
11+
{
12+
var fields = typeof(S7Consts).GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
13+
errorsDictionary = fields.Where(x => x.Name.StartsWith("err")).ToDictionary(x => (int)x.GetValue(null), x => x.Name);
14+
}
15+
16+
public static string GetErrorText(int error)
17+
{
18+
if (errorsDictionary.TryGetValue(error, out var text))
19+
return text;
20+
return null;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)