forked from microsoft/GraphEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigurationSetting.cs
More file actions
56 lines (55 loc) · 1.58 KB
/
ConfigurationSetting.cs
File metadata and controls
56 lines (55 loc) · 1.58 KB
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
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Trinity.Configuration
{
public class ConfigurationSetting
{
public ConfigurationSetting(System.Xml.Linq.XAttribute attribute)
: this(attribute.Name.LocalName, attribute.Value) { }
public ConfigurationSetting(string key, string value)
{
Key = key;
Literal = value;
}
public string Key { get; private set; }
public string Literal { get; private set; }
public object GetValue(System.Type type)
{
if (type.IsEnum)
{
return Enum.Parse(type, Literal);
}
else if (type == typeof(Int32))
{
return Int32.Parse(Literal);
}
else if (type == typeof(Int64))
{
return Int64.Parse(Literal);
}
else if (type == typeof(string))
{
return Literal;
}
else if (type == typeof(bool))
{
return bool.Parse(Literal);
}
else if (type == typeof(float))
{
return float.Parse(Literal);
}
else if (type == typeof(double))
{
return double.Parse(Literal);
}
else
{
throw new ArgumentException(String.Format("Unsupported configuration value type: {0}", type.ToString()), "type");
}
}
}
}