|
5 | 5 | using System.Linq; |
6 | 6 | using System.Text; |
7 | 7 |
|
8 | | -namespace IGLib |
9 | | -{ |
10 | | - |
11 | | - /// <summary>Dummy identity parser - just returns the original string when parsing a string value from a string.</summary> |
12 | | - internal sealed class IdentityStringParser : IStringParser<string> |
13 | | - { |
14 | | - public bool TryParse(string text, out string value) |
15 | | - { |
16 | | - value = text; |
17 | | - return true; |
18 | | - } |
19 | | - } |
20 | | - |
21 | | - /// <summary>Parses boolean from a striring.</summary> |
22 | | - internal sealed class BooleanStringParser : IStringParser<bool> |
23 | | - { |
24 | | - public bool TryParse(string text, out bool value) => |
25 | | - bool.TryParse(text, out value); |
26 | | - } |
27 | | - |
28 | | - |
29 | | - internal sealed class Int32StringParser : IStringParser<int> |
30 | | - { |
31 | | - private readonly IFormatProvider _formatProvider; |
32 | | - |
33 | | - public Int32StringParser(IFormatProvider formatProvider) |
34 | | - { |
35 | | - _formatProvider = formatProvider; |
36 | | - } |
37 | | - |
38 | | - public bool TryParse(string text, out int value) => |
39 | | - int.TryParse(text, NumberStyles.Integer, _formatProvider, out value); |
40 | | - } |
41 | | - |
42 | | - |
43 | | - |
44 | | - internal sealed class DecimalStringParser : IStringParser<decimal> |
45 | | - { |
46 | | - private readonly IFormatProvider _formatProvider; |
47 | | - |
48 | | - public DecimalStringParser(IFormatProvider formatProvider) |
49 | | - { |
50 | | - _formatProvider = formatProvider; |
51 | | - } |
52 | | - |
53 | | - public bool TryParse(string text, out decimal value) => |
54 | | - decimal.TryParse( |
55 | | - text, |
56 | | - NumberStyles.Number, |
57 | | - _formatProvider, |
58 | | - out value); |
59 | | - } |
60 | | - |
| 8 | +namespace IGLib; |
61 | 9 |
|
62 | | - internal sealed class DoubleStringParser : IStringParser<double> |
63 | | - { |
64 | | - private readonly IFormatProvider _formatProvider; |
65 | | - |
66 | | - public DoubleStringParser(IFormatProvider formatProvider) |
67 | | - { |
68 | | - _formatProvider = formatProvider; |
69 | | - } |
70 | | - |
71 | | - public bool TryParse(string text, out double value) => |
72 | | - double.TryParse( |
73 | | - text, |
74 | | - NumberStyles.Float | NumberStyles.AllowThousands, |
75 | | - _formatProvider, |
76 | | - out value); |
77 | | - } |
78 | | - |
79 | | - |
80 | | - |
81 | | - internal sealed class DateTimeStringParser : IStringParser<DateTime> |
82 | | - { |
83 | | - private readonly IFormatProvider _formatProvider; |
84 | | - |
85 | | - public DateTimeStringParser(IFormatProvider formatProvider) |
86 | | - { |
87 | | - _formatProvider = formatProvider; |
88 | | - } |
89 | | - |
90 | | - public bool TryParse(string text, out DateTime value) => |
91 | | - DateTime.TryParse( |
92 | | - text, |
93 | | - _formatProvider, |
94 | | - DateTimeStyles.None, |
95 | | - out value); |
96 | | - } |
97 | 10 |
|
98 | | - |
99 | | - internal sealed class GuidStringParser : IStringParser<Guid> |
| 11 | +/// <summary>Dummy identity parser - just returns the original string when parsing a string value from a string.</summary> |
| 12 | +internal sealed class IdentityStringParser : IStringParser<string> |
| 13 | +{ |
| 14 | + public bool TryParse(string text, out string value) |
100 | 15 | { |
101 | | - public bool TryParse(string text, out Guid value) => |
102 | | - Guid.TryParse(text, out value); |
| 16 | + value = text; |
| 17 | + return true; |
103 | 18 | } |
| 19 | +} |
104 | 20 |
|
105 | | - |
106 | | - internal sealed class TimeSpanStringParser : IStringParser<TimeSpan> |
| 21 | +internal sealed class BooleanStringParser : IStringParser<bool> |
| 22 | +{ |
| 23 | + public bool TryParse(string text, out bool value) |
107 | 24 | { |
108 | | - private readonly IFormatProvider _formatProvider; |
109 | | - |
110 | | - public TimeSpanStringParser(IFormatProvider formatProvider) |
111 | | - { |
112 | | - _formatProvider = formatProvider; |
113 | | - } |
114 | | - |
115 | | - public bool TryParse(string text, out TimeSpan value) => |
116 | | - TimeSpan.TryParse(text, _formatProvider, out value); |
| 25 | + return bool.TryParse(text, out value); |
117 | 26 | } |
| 27 | +} |
118 | 28 |
|
119 | 29 |
|
120 | 30 |
|
121 | | - |
122 | | -} |
0 commit comments