From 0f360bfb3331c6273f7a151003f79722045942ed Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Mon, 8 Jun 2015 12:00:57 +0200 Subject: [PATCH] added ToDouble as Extension Method for Strings --- VectoCore/Utils/DataRowExtensionMethods.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/VectoCore/Utils/DataRowExtensionMethods.cs b/VectoCore/Utils/DataRowExtensionMethods.cs index b0ad2dd991..10eb593944 100644 --- a/VectoCore/Utils/DataRowExtensionMethods.cs +++ b/VectoCore/Utils/DataRowExtensionMethods.cs @@ -1,6 +1,9 @@ using System; +using System.Collections; +using System.Collections.Generic; using System.Data; using System.Globalization; +using System.Linq; using TUGraz.VectoCore.Exceptions; namespace TUGraz.VectoCore.Utils @@ -32,7 +35,7 @@ namespace TUGraz.VectoCore.Utils public static double ParseDouble(this DataRow row, DataColumn column) { try { - return double.Parse(row.Field<string>(column), CultureInfo.InvariantCulture); + return row.Field<string>(column).ToDouble(); } catch (IndexOutOfRangeException e) { throw new VectoException(string.Format("Field {0} was not found in DataRow.", column), e); } catch (NullReferenceException e) { @@ -49,5 +52,15 @@ namespace TUGraz.VectoCore.Utils throw new VectoException(string.Format("Field {0}: {1}", column, e.Message), e); } } + + public static double ToDouble(this string self) + { + return double.Parse(self, CultureInfo.InvariantCulture); + } + + public static IEnumerable<double> ToDouble(this IEnumerable<string> self) + { + return self.Select(ToDouble); + } } } \ No newline at end of file -- GitLab