-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.cs
32 lines (29 loc) · 915 Bytes
/
Util.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ObjectMatcher
{
public class Util
{
//http://stackoverflow.com/a/606381/1884140
public static object ParseString(string str)
{
int intValue;
double doubleValue;
DateTime dateTimeValue;
bool boolValue;
// Place checks higher if if-else statement to give higher priority to type.
if (int.TryParse(str, out intValue))
return intValue;
else if (double.TryParse(str, out doubleValue))
return doubleValue;
else if (DateTime.TryParse(str, out dateTimeValue))
return dateTimeValue;
else if (bool.TryParse(str, out boolValue))
return boolValue;
return null;
}
}
}