1
0

feat: use lightweight OneOf instead of LanguageExt

This commit is contained in:
2026-04-10 21:05:56 +08:00
parent 1f4d70c766
commit a800b53188
3 changed files with 10 additions and 14 deletions

View File

@@ -17,7 +17,7 @@
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.4.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="DotNetZip" Version="1.9.1.8" />
<PackageReference Include="LanguageExt.Core" Version="4.4.9" />
<PackageReference Include="OneOf" Version="3.0.271" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="10.0.5" />
</ItemGroup>

View File

@@ -17,20 +17,16 @@ namespace BallanceTasEditor.Frontend.Validator {
private readonly IValidator<TIn, TOut> m_Validator;
public ValidationResult? Validate(TIn value, ValidationContext validationContext) {
// YYC MARK:
// Due to the shitty behavior of LanguageExt
// which do not allow I return nullable class from Match,
// I was forcely use MatchUnsafe.
return m_Validator.Validate(value).MatchUnsafe(
Left: v => ValidationResult.Success,
Right: err => new ValidationResult(err)
return m_Validator.Validate(value).Match(
v => ValidationResult.Success,
err => new ValidationResult(err)
);
}
public TOut Conclude(TIn value) {
return m_Validator.Validate(value).Match(
Left: v => v,
Right: _ => throw new InvalidOperationException("Can not unwrap an error casting.")
v => v,
_ => throw new InvalidOperationException("Can not unwrap an error casting.")
);
}

View File

@@ -1,4 +1,4 @@
using LanguageExt;
using OneOf;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -8,11 +8,11 @@ using System.Threading.Tasks;
namespace BallanceTasEditor.Frontend.Validator {
public interface IValidator<TIn, TOut> {
Either<TOut, string> Validate(TIn value);
OneOf<TOut, string> Validate(TIn value);
}
public sealed class FpsValidator : IValidator<string, uint> {
public Either<uint, string> Validate(string value) {
public OneOf<uint, string> Validate(string value) {
if (uint.TryParse(value, System.Globalization.CultureInfo.InvariantCulture, out uint fps)) {
if (Backend.FpsConverter.IsValidFps(fps)) {
return fps;
@@ -26,7 +26,7 @@ namespace BallanceTasEditor.Frontend.Validator {
}
public sealed class CountValidator : IValidator<string, int> {
public Either<int, string> Validate(string value) {
public OneOf<int, string> Validate(string value) {
if (int.TryParse(value, System.Globalization.CultureInfo.InvariantCulture, out int count)) {
if (count > 0) {
return count;