Huge refactor; Passing tests

This commit is contained in:
2024-01-13 01:31:30 +01:00
parent 3e307c27fa
commit 09fa3b8734
18 changed files with 577 additions and 162 deletions
@@ -0,0 +1,16 @@
namespace SimpleHttpServer.Types.ParameterConverters;
internal class BoolParsableParameterConverter : IParameterConverter {
public bool TryConvertFromString(string value, out object result) {
var normalized = value.ToLowerInvariant();
if (normalized is "true" or "1") {
result = true;
return true;
} else if (normalized is "false" or "0") {
result = false;
return true;
} else {
result = false;
return false;
}
}
}
@@ -0,0 +1,10 @@
using System.Diagnostics.CodeAnalysis;
namespace SimpleHttpServer.Types.ParameterConverters;
internal class ParsableParameterConverter<T> : IParameterConverter where T : IParsable<T> {
public bool TryConvertFromString(string value, [NotNullWhen(true)] out object result) {
bool ok = T.TryParse(value, null, out T? res);
result = res!;
return ok;
}
}