Skip to content

Commit bbfe408

Browse files
committed
Moved Classes TypeSwitch and Helper to seperate class files
1 parent 98800fd commit bbfe408

File tree

4 files changed

+58
-31
lines changed

4 files changed

+58
-31
lines changed

ArgumentParser/ArgumentParser.cs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
namespace ArgumentParser
1111
{
12+
13+
/// <summary>
14+
/// Class for parsing TerminalInput Arguments and call defined Method in a Object with it's parameters
15+
/// </summary>
1216
public class ArgumentParser
1317
{
1418

@@ -164,35 +168,4 @@ private object ParseValue(string input, Type destinationType)
164168
#endregion
165169
}
166170

167-
public class TypeSwitch
168-
{
169-
170-
Dictionary<Type, Func<string, object>> matches = new Dictionary<Type, Func<string, object>>();
171-
public TypeSwitch Case<T>(Func<string, object> action) { matches.Add(typeof(T), (x) => { return action(x); }); return this; }
172-
public object Switch(Type x, string input) { return matches[x](input); }
173-
}
174-
175-
public static class Helper
176-
{
177-
public static bool IsNumericType(this object o)
178-
{
179-
switch (Type.GetTypeCode(o.GetType()))
180-
{
181-
case TypeCode.Byte:
182-
case TypeCode.SByte:
183-
case TypeCode.UInt16:
184-
case TypeCode.UInt32:
185-
case TypeCode.UInt64:
186-
case TypeCode.Int16:
187-
case TypeCode.Int32:
188-
case TypeCode.Int64:
189-
case TypeCode.Decimal:
190-
case TypeCode.Double:
191-
case TypeCode.Single:
192-
return true;
193-
default:
194-
return false;
195-
}
196-
}
197-
}
198171
}

ArgumentParser/ArgumentParser.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242
<ItemGroup>
4343
<Compile Include="ArgumentParser.cs" />
4444
<Compile Include="ArgumentParserException.cs" />
45+
<Compile Include="Helper.cs" />
4546
<Compile Include="ParameterAttribute.cs" />
4647
<Compile Include="CommandAttribute.cs" />
4748
<Compile Include="Properties\AssemblyInfo.cs" />
49+
<Compile Include="TypeSwitch.cs" />
4850
</ItemGroup>
4951
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5052
</Project>

ArgumentParser/Helper.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ArgumentParser
8+
{
9+
#region Helper
10+
public static class Helper
11+
{
12+
public static bool IsNumericType(this object o)
13+
{
14+
switch (Type.GetTypeCode(o.GetType()))
15+
{
16+
case TypeCode.Byte:
17+
case TypeCode.SByte:
18+
case TypeCode.UInt16:
19+
case TypeCode.UInt32:
20+
case TypeCode.UInt64:
21+
case TypeCode.Int16:
22+
case TypeCode.Int32:
23+
case TypeCode.Int64:
24+
case TypeCode.Decimal:
25+
case TypeCode.Double:
26+
case TypeCode.Single:
27+
return true;
28+
default:
29+
return false;
30+
}
31+
}
32+
}
33+
#endregion
34+
}

ArgumentParser/TypeSwitch.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ArgumentParser
8+
{
9+
#region TypeSwitch
10+
public class TypeSwitch
11+
{
12+
13+
Dictionary<Type, Func<string, object>> matches = new Dictionary<Type, Func<string, object>>();
14+
public TypeSwitch Case<T>(Func<string, object> action) { matches.Add(typeof(T), (x) => { return action(x); }); return this; }
15+
public object Switch(Type x, string input) { return matches[x](input); }
16+
}
17+
#endregion
18+
}

0 commit comments

Comments
 (0)