Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 0f360bfb authored by Michael KRISPER's avatar Michael KRISPER
Browse files

added ToDouble as Extension Method for Strings

parent 7d348cbb
No related branches found
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment