From 6b7c275daef727966131563ed818d069102228b6 Mon Sep 17 00:00:00 2001 From: Roman Shapiro Date: Wed, 16 Mar 2016 15:33:15 +0600 Subject: [PATCH] Missing fields fix --- .../BitmapFontLoader.cs | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Cyotek.Drawing.BitmapFont/BitmapFontLoader.cs b/src/Cyotek.Drawing.BitmapFont/BitmapFontLoader.cs index ef354b9..92f184d 100644 --- a/src/Cyotek.Drawing.BitmapFont/BitmapFontLoader.cs +++ b/src/Cyotek.Drawing.BitmapFont/BitmapFontLoader.cs @@ -145,10 +145,23 @@ public static BitmapFont LoadFontFromXmlFile(string fileName) /// /// The array of parts. /// The name of the value to return. + /// Default value(if the key doesnt exist or can't be parsed) /// - internal static bool GetNamedBool(string[] parts, string name) + internal static bool GetNamedBool(string[] parts, string name, bool defaultValue = false) { - return GetNamedInt(parts, name) != 0; + var s = GetNamedString(parts, name); + + bool result; + int v; + if (int.TryParse(s, out v)) + { + result = v > 0; + } else + { + result = defaultValue; + } + + return result; } /// @@ -156,10 +169,19 @@ internal static bool GetNamedBool(string[] parts, string name) /// /// The array of parts. /// The name of the value to return. + /// Default value(if the key doesnt exist or can't be parsed) /// - internal static int GetNamedInt(string[] parts, string name) + internal static int GetNamedInt(string[] parts, string name, int defaultValue = 0) { - return Convert.ToInt32(GetNamedString(parts, name)); + var s = GetNamedString(parts, name); + + int result; + if (!int.TryParse(s, out result)) + { + result = defaultValue; + } + + return result; } ///