Skip to content

Commit 52ab67e

Browse files
committed
[r] switch to StringConverter
1 parent 97488e2 commit 52ab67e

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

src/Simplify.Web/Controllers/V2/Routing/Controller2PathParser.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text.RegularExpressions;
55
using Simplify.Web.Controllers.Meta.Routing;
6+
using Simplify.Web.System;
67

78
namespace Simplify.Web.Controllers.V2.Routing;
89

@@ -12,18 +13,6 @@ public static class Controller2PathParser
1213

1314
private static readonly char[] RequiredSymbols = ['{', '}'];
1415

15-
public static IList<Type> SupportedTypes { get; } =
16-
[
17-
typeof(string),
18-
typeof(int),
19-
typeof(decimal),
20-
typeof(bool),
21-
typeof(string[]),
22-
typeof(int[]),
23-
typeof(decimal[]),
24-
typeof(bool[])
25-
];
26-
2716
/// <summary>
2817
/// Parses the specified controller path.
2918
/// </summary>
@@ -70,11 +59,10 @@ private static PathItem ParsePathParameter(string item, string controllerPath, I
7059
if (!invokeMethodParameters.TryGetValue(parameterName, out var parameterType))
7160
return new PathParameter(parameterName, typeof(string));
7261

73-
if (!SupportedTypes.Contains(parameterType))
74-
throw new ControllerRouteException($"Unsupported parameter type '{parameterType.Name}' of parameter '{parameterName}'. Can be one of: {GetTypeNamesAsString()}");
62+
if (!StringConverter.ValueConverters.ContainsKey(parameterType))
63+
throw new ControllerRouteException(
64+
$"Unsupported parameter type '{parameterType.Name}' of parameter '{parameterName}'. Can be one of: {StringConverter.GetSupportedTypeNamesAsString()}");
7565

7666
return new PathParameter(parameterName, parameterType);
7767
}
78-
79-
private static string GetTypeNamesAsString() => string.Join(", ", SupportedTypes.Select(type => type.Name));
8068
}

src/Simplify.Web/System/StringConverter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Simplify.Web.System;
66

77
public static class StringConverter
88
{
9-
private static readonly Dictionary<Type, Func<string, object?>> ValueConverters =
9+
public static readonly Dictionary<Type, Func<string, object?>> ValueConverters =
1010
new()
1111
{
1212
{ typeof(string), sourceValue => sourceValue },
@@ -27,6 +27,8 @@ public static class StringConverter
2727
? converter(sourceValue)
2828
: null;
2929

30+
public static string GetSupportedTypeNamesAsString() => string.Join(", ", ValueConverters.Keys.Select(type => type.Name));
31+
3032
private static object? GetIntParameterValue(string source)
3133
{
3234
if (!int.TryParse(source, out var buffer))

0 commit comments

Comments
 (0)