Skip to content

Commit 90dd731

Browse files
committed
Fix #88 Unable to parse 0 or 1 with GetBoolean()
1 parent 64dd1da commit 90dd731

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Source/Shared/Models/Collections/SettingsDictionary.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,26 @@ public bool GetBoolean(string name) {
3232
}
3333

3434
public bool GetBoolean(string name, bool @default) {
35-
bool value;
3635
string temp = null;
37-
38-
bool result = name != null && TryGetValue(name, out temp);
39-
if (!result)
36+
if (String.IsNullOrWhiteSpace(name) || !TryGetValue(name, out temp))
37+
return @default;
38+
39+
if (String.IsNullOrEmpty(temp))
4040
return @default;
4141

42-
result = bool.TryParse(temp, out value);
43-
return result ? value : @default;
42+
temp = temp.ToLowerInvariant().Trim();
43+
44+
bool value;
45+
if (bool.TryParse(temp, out value))
46+
return value;
47+
48+
if (String.Equals(temp, "yes") || String.Equals(temp, "1"))
49+
return true;
50+
51+
if (String.Equals(temp, "no") || String.Equals(temp, "0"))
52+
return false;
53+
54+
return @default;
4455
}
4556

4657
public int GetInt32(string name) {

0 commit comments

Comments
 (0)