/
Extensions.cs
48 lines (44 loc) · 1.2 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace HydroNumerics.Core
{
public static class Extensions
{
public static bool? SafeParseBool(this XElement Conf, string AttributeName)
{
var attrib = Conf.Attribute(AttributeName);
if (attrib == null)
return null;
else
return bool.Parse(attrib.Value);
}
public static string SafeParseString(this XElement Conf, string AttributeName)
{
var attrib = Conf.Attribute(AttributeName);
if (attrib == null)
return null;
else
return attrib.Value;
}
public static double? SafeParseDouble(this XElement Conf, string AttributeName)
{
var attrib = Conf.Attribute(AttributeName);
if (attrib == null)
return null;
else
return double.Parse(attrib.Value);
}
public static int? SafeParseInt(this XElement Conf, string AttributeName)
{
var attrib = Conf.Attribute(AttributeName);
if (attrib == null)
return null;
else
return int.Parse(attrib.Value);
}
}
}