Skip to content

Commit a7af967

Browse files
committed
Added support for float conversion
1 parent 93d4fb4 commit a7af967

4 files changed

Lines changed: 26 additions & 9 deletions

File tree

src/libArgument/libArgument.userprefs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
33
<MonoDevelop.Ide.Workbench ActiveDocument="libArgument\ArgumentParser.cs">
44
<Files>
5-
<File FileName="libArgument\ArgumentParser.cs" Line="19" Column="19" />
5+
<File FileName="libArgument\ArgumentParser.cs" Line="23" Column="23" />
66
</Files>
77
</MonoDevelop.Ide.Workbench>
88
<MonoDevelop.Ide.DebuggingService.Breakpoints>

src/libArgument/libArgument/ArgumentParser.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using System.Reflection;
56
using Codeaddicts.libArgument.Attributes;
@@ -41,7 +42,7 @@ public static class ArgumentParser
4142
throw new ArgumentOutOfRangeException (string.Format ("Parameter of argument {0} out of range.", str));
4243
switch (cast.Type) {
4344
case CastingType.Boolean:
44-
var bool_result = false;
45+
bool bool_result;
4546
if (!Boolean.TryParse (args [index], out bool_result))
4647
throw new InvalidCastException (string.Format ("Can't cast parameter of argument {0} to Boolean.", str));
4748
field.SetValue (options, bool_result);
@@ -50,41 +51,47 @@ public static class ArgumentParser
5051
field.SetValue (options, args [index]);
5152
return;
5253
case CastingType.Int32:
53-
var int32_result = 0;
54+
int int32_result;
5455
if (!Int32.TryParse (args [index], out int32_result))
5556
throw new InvalidCastException (string.Format ("Can't cast parameter of argument {0} to Int32.", str));
5657
field.SetValue (options, int32_result);
5758
return;
5859
case CastingType.Int64:
59-
var int64_result = 0L;
60+
long int64_result;
6061
if (!Int64.TryParse (args [index], out int64_result))
6162
throw new InvalidCastException (string.Format ("Can't cast parameter of argument {0} to Int64.", str));
6263
field.SetValue (options, int64_result);
6364
return;
6465
case CastingType.UInt32:
65-
var uint32_result = 0u;
66+
uint uint32_result;
6667
if (!UInt32.TryParse (args [index], out uint32_result))
6768
throw new InvalidCastException (string.Format ("Can't cast parameter of argument {0} to UInt32.", str));
6869
field.SetValue (options, uint32_result);
6970
return;
7071
case CastingType.UInt64:
71-
var uint64_result = 0uL;
72+
ulong uint64_result;
7273
if (!UInt64.TryParse (args [index], out uint64_result))
7374
throw new InvalidCastException (string.Format ("Can't cast parameter of argument {0} to UInt64.", str));
7475
field.SetValue (options, uint64_result);
7576
return;
7677
case CastingType.Long:
77-
var long_result = 0L;
78+
long long_result;
7879
if (!long.TryParse (args [index], out long_result))
7980
throw new InvalidCastException (string.Format ("Can't cast parameter of argument {0} to long.", str));
8081
field.SetValue (options, long_result);
8182
return;
8283
case CastingType.ULong:
83-
var ulong_result = 0uL;
84+
ulong ulong_result;
8485
if (!ulong.TryParse (args [index], out ulong_result))
8586
throw new InvalidCastException (string.Format ("Can't cast parameter of argument {0} to ulong.", str));
8687
field.SetValue (options, ulong_result);
8788
return;
89+
case CastingType.Float:
90+
float float_result;
91+
if (!float.TryParse (args [index], NumberStyles.Float, CultureInfo.InvariantCulture, out float_result))
92+
throw new InvalidCastException (string.Format ("Can't cast parameter of argument {0} to float.", str));
93+
field.SetValue (options, float_result);
94+
return;
8895
}
8996
}
9097
}

src/libArgument/libArgument/Attributes/CastingType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public enum CastingType {
1111
UInt32,
1212
UInt64,
1313
Long,
14-
ULong
14+
ULong,
15+
Float
1516
}
1617
}
1718

src/libArgument/libArgument/libArgument.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,13 @@
4242
<ItemGroup>
4343
<Folder Include="Attributes\" />
4444
</ItemGroup>
45+
<ProjectExtensions>
46+
<MonoDevelop>
47+
<Properties>
48+
<Policies>
49+
<DotNetNamingPolicy DirectoryNamespaceAssociation="Hierarchical" ResourceNamePolicy="FileFormatDefault" />
50+
</Policies>
51+
</Properties>
52+
</MonoDevelop>
53+
</ProjectExtensions>
4554
</Project>

0 commit comments

Comments
 (0)