| 18 |
clempaul |
1 |
using System; |
|
|
2 |
using System.Xml.Linq; |
|
|
3 |
|
|
|
4 |
namespace clempaul |
|
|
5 |
{ |
| 19 |
clempaul |
6 |
internal static class DreamhostExtensionMethods |
| 18 |
clempaul |
7 |
{ |
|
|
8 |
internal static bool AsBool(this XElement element) |
|
|
9 |
{ |
|
|
10 |
if (element == null) |
|
|
11 |
{ |
|
|
12 |
return false; |
|
|
13 |
} |
|
|
14 |
else |
|
|
15 |
{ |
| 24 |
clempaul |
16 |
return !element.Value.Equals("0") && !element.Value.Equals("no") && !element.Value.Equals("N"); |
| 18 |
clempaul |
17 |
} |
|
|
18 |
} |
|
|
19 |
|
|
|
20 |
internal static string AsString(this XElement element) |
|
|
21 |
{ |
|
|
22 |
if (element == null) |
|
|
23 |
{ |
|
|
24 |
return string.Empty; |
|
|
25 |
} |
|
|
26 |
else |
|
|
27 |
{ |
|
|
28 |
return element.Value; |
|
|
29 |
} |
|
|
30 |
} |
|
|
31 |
|
|
|
32 |
internal static DateTime AsDateTime(this XElement element) |
|
|
33 |
{ |
|
|
34 |
if (element == null) |
|
|
35 |
{ |
|
|
36 |
return new DateTime(); |
|
|
37 |
} |
|
|
38 |
else |
|
|
39 |
{ |
|
|
40 |
return DateTime.Parse(element.Value); |
|
|
41 |
} |
|
|
42 |
} |
|
|
43 |
|
|
|
44 |
internal static int AsInt(this XElement element) { |
|
|
45 |
if (element == null) |
|
|
46 |
{ |
|
|
47 |
return 0; |
|
|
48 |
} |
|
|
49 |
else |
|
|
50 |
{ |
|
|
51 |
return int.Parse(element.Value); |
|
|
52 |
} |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
internal static double AsDouble(this XElement element) |
|
|
56 |
{ |
|
|
57 |
if (element == null) |
|
|
58 |
{ |
|
|
59 |
return 0; |
|
|
60 |
} |
|
|
61 |
else |
|
|
62 |
{ |
|
|
63 |
return double.Parse(element.Value); |
|
|
64 |
} |
|
|
65 |
} |
|
|
66 |
|
| 19 |
clempaul |
67 |
internal static string AsYYYYMMDD(this DateTime? value) |
|
|
68 |
{ |
|
|
69 |
return ((DateTime)value).ToString("YYYY-MM-DD"); |
|
|
70 |
} |
|
|
71 |
|
| 32 |
clempaul |
72 |
internal static string AsTimestamp(this DateTime? value) |
|
|
73 |
{ |
|
|
74 |
return ((DateTime)value).ToString("YYYY-MM-DD HH:mm"); |
|
|
75 |
} |
|
|
76 |
|
| 19 |
clempaul |
77 |
internal static string AsBit(this bool value) |
|
|
78 |
{ |
|
|
79 |
if (value) |
|
|
80 |
{ |
|
|
81 |
return "1"; |
|
|
82 |
} |
|
|
83 |
else |
|
|
84 |
{ |
|
|
85 |
return "0"; |
|
|
86 |
} |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
internal static string AsBit(this bool? value) |
|
|
90 |
{ |
|
|
91 |
if ((bool)value) |
|
|
92 |
{ |
|
|
93 |
return "1"; |
|
|
94 |
} |
|
|
95 |
else |
|
|
96 |
{ |
|
|
97 |
return "0"; |
|
|
98 |
} |
|
|
99 |
} |
| 24 |
clempaul |
100 |
|
|
|
101 |
internal static string AsYN(this bool? value) |
|
|
102 |
{ |
|
|
103 |
if ((bool)value) |
|
|
104 |
{ |
|
|
105 |
return "Y"; |
|
|
106 |
} |
|
|
107 |
else |
|
|
108 |
{ |
|
|
109 |
return "N"; |
|
|
110 |
} |
|
|
111 |
} |
|
|
112 |
|
|
|
113 |
internal static string Asyesno(this bool? value) |
|
|
114 |
{ |
|
|
115 |
if ((bool)value) |
|
|
116 |
{ |
|
|
117 |
return "yes"; |
|
|
118 |
} |
|
|
119 |
else |
|
|
120 |
{ |
|
|
121 |
return "no"; |
|
|
122 |
} |
|
|
123 |
} |
| 18 |
clempaul |
124 |
} |
|
|
125 |
} |