Huge refactor; Passing tests
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user