Skip to content

Commit 78e36bf

Browse files
committed
Added case insensivity
1 parent db85ca4 commit 78e36bf

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

Raspberry.System/Board.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Generic;
55
using System.Globalization;
66
using System.IO;
7-
using System.Linq;
87

98
#endregion
109

@@ -19,9 +18,9 @@ public class Board
1918
#region Fields
2019

2120
private static readonly Lazy<Board> board = new Lazy<Board>(LoadBoard);
22-
private readonly Dictionary<string, string> settings;
2321

24-
private string[] raspberryPiProcessor = new string[] { "BCM2708", "BCM2709" };
22+
private readonly Dictionary<string, string> settings;
23+
private readonly HashSet<string> raspberryPiProcessors = new HashSet<string>(new[]{ "BCM2708", "BCM2709" }, StringComparer.InvariantCultureIgnoreCase);
2524

2625
#endregion
2726

@@ -52,7 +51,7 @@ public static Board Current
5251
/// </value>
5352
public bool IsRaspberryPi
5453
{
55-
get { return (Array.IndexOf(raspberryPiProcessor, Processor) >= 0); }
54+
get { return raspberryPiProcessors.Contains(Processor); }
5655
}
5756

5857
/// <summary>
@@ -76,7 +75,9 @@ public int Firmware
7675
{
7776
string revision;
7877
int firmware;
79-
if (settings.TryGetValue("Revision", out revision) && !string.IsNullOrEmpty(revision) && int.TryParse(revision, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out firmware))
78+
if (settings.TryGetValue("Revision", out revision)
79+
&& !string.IsNullOrEmpty(revision)
80+
&& int.TryParse(revision, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out firmware))
8081
return firmware;
8182

8283
return 0;
@@ -90,7 +91,8 @@ public string SerialNumber
9091
{
9192
get {
9293
string serial;
93-
if (settings.TryGetValue("Serial", out serial) && !string.IsNullOrEmpty(serial))
94+
if (settings.TryGetValue("Serial", out serial)
95+
&& !string.IsNullOrEmpty(serial))
9496
return serial;
9597

9698
return null;
@@ -199,29 +201,28 @@ private static Board LoadBoard()
199201
try
200202
{
201203
const string filePath = "/proc/cpuinfo";
202-
string[] cpuInfo = File.ReadAllLines(filePath);
203-
Dictionary<string, string> settings = new Dictionary<string, string>();
204-
string suffix = "";
204+
205+
var cpuInfo = File.ReadAllLines(filePath);
206+
var settings = new Dictionary<string, string>();
207+
var suffix = string.Empty;
208+
205209
foreach(var l in cpuInfo)
206210
{
207211
var separator = l.IndexOf(':');
208-
string key = l;
209-
string val = null;
212+
210213
if (!string.IsNullOrWhiteSpace(l) && separator > 0)
211214
{
212-
key = l.Substring(0, separator).Trim();
213-
val = l.Substring(separator + 1).Trim();
214-
if (String.Compare(key, "processor", true) == 0)
215-
{
215+
var key = l.Substring(0, separator).Trim();
216+
var val = l.Substring(separator + 1).Trim();
217+
if (string.Equals(key, "processor", StringComparison.InvariantCultureIgnoreCase))
216218
suffix = "." + val;
217-
}
219+
218220
settings.Add(key + suffix, val);
219221
}
220222
else
221-
{
222223
suffix = "";
223-
}
224224
}
225+
225226
return new Board(settings);
226227
}
227228
catch

0 commit comments

Comments
 (0)