From eb9beb131bd03673faebbfe12a7098d4738e2256 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Wed, 7 Sep 2016 17:51:57 +0200
Subject: [PATCH] additional utility methods (used by the GUI)

---
 .../VectoCommon/Utils/DoubleExtensionMethods.cs    | 14 ++++++++++++++
 VectoCommon/VectoCommon/Utils/SI.cs                |  9 ++++++++-
 .../VectoCommon/Utils/StringExtensionMethods.cs    | 12 ++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/VectoCommon/VectoCommon/Utils/DoubleExtensionMethods.cs b/VectoCommon/VectoCommon/Utils/DoubleExtensionMethods.cs
index fb05531236..a7f09db14a 100644
--- a/VectoCommon/VectoCommon/Utils/DoubleExtensionMethods.cs
+++ b/VectoCommon/VectoCommon/Utils/DoubleExtensionMethods.cs
@@ -32,6 +32,7 @@
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Globalization;
 using System.Linq;
 
 namespace TUGraz.VectoCommon.Utils
@@ -215,6 +216,11 @@ namespace TUGraz.VectoCommon.Utils
 		{
 			return self.Select(x => x.SI<T>());
 		}
+
+		public static string ToGUIFormat(this double self)
+		{
+			return self.ToString(CultureInfo.InvariantCulture);
+		}
 	}
 
 	public static class FloatExtensionMethods
@@ -225,4 +231,12 @@ namespace TUGraz.VectoCommon.Utils
 			return SIBase<T>.Create(value);
 		}
 	}
+
+	public static class IntegerExtensionMethods
+	{
+		public static string ToGUIFormat(this int self)
+		{
+			return self.ToString();
+		}
+	}
 }
\ No newline at end of file
diff --git a/VectoCommon/VectoCommon/Utils/SI.cs b/VectoCommon/VectoCommon/Utils/SI.cs
index 30bfd20894..f95bd88e7d 100644
--- a/VectoCommon/VectoCommon/Utils/SI.cs
+++ b/VectoCommon/VectoCommon/Utils/SI.cs
@@ -641,6 +641,7 @@ namespace TUGraz.VectoCommon.Utils
 		{
 			return Val * 3.6;
 		}
+
 		/// <summary>
 		/// Implements the operator /.
 		/// </summary>
@@ -833,8 +834,9 @@ namespace TUGraz.VectoCommon.Utils
 		/// <param name="val">The value of the SI object.</param>
 		public static T Create(double val)
 		{
-			if (val == 0)
+			if (val == 0) {
 				return ZeroPrototype;
+			}
 
 			return Constructor(val);
 		}
@@ -2249,5 +2251,10 @@ namespace TUGraz.VectoCommon.Utils
 
 			return (Val * outputFactor.Value).ToString("F" + decimals.Value, CultureInfo.InvariantCulture);
 		}
+
+		public string ToGUIFormat()
+		{
+			return Val.ToGUIFormat();
+		}
 	}
 }
\ No newline at end of file
diff --git a/VectoCommon/VectoCommon/Utils/StringExtensionMethods.cs b/VectoCommon/VectoCommon/Utils/StringExtensionMethods.cs
index 5c56ba1f55..c78ef4f209 100644
--- a/VectoCommon/VectoCommon/Utils/StringExtensionMethods.cs
+++ b/VectoCommon/VectoCommon/Utils/StringExtensionMethods.cs
@@ -51,6 +51,18 @@ namespace TUGraz.VectoCommon.Utils
 			}
 		}
 
+		public static int ToInt(this string self, int? defaultValue = null)
+		{
+			try {
+				return int.Parse(self, CultureInfo.InvariantCulture);
+			} catch (FormatException) {
+				if (defaultValue.HasValue) {
+					return defaultValue.Value;
+				}
+				throw;
+			}
+		}
+
 		public static bool ToBoolean(this string self)
 		{
 			if (string.IsNullOrEmpty(self)) {
-- 
GitLab