prevent dup wallets
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Error(string Code, string Message)
|
||||
{
|
||||
public static readonly Error None = new(string.Empty, string.Empty);
|
||||
|
||||
public static readonly Error Null = new("Error.NullValue", "The specified result value is null.");
|
||||
|
||||
public static readonly Error ConditionNotMet = new("Error.ConditionNotMet", "The specified condition was not met.");
|
||||
|
||||
public static readonly Error Duplicated = new("Error.Duplicated", "The specified item already exists.");
|
||||
|
||||
public static readonly Error Failure = new("Error.Failure", "The operation has failed.");
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Result<TValue> :
|
||||
Result
|
||||
{
|
||||
private readonly TValue? value;
|
||||
|
||||
protected internal Result(TValue? value, bool isSuccess, Error error)
|
||||
: base(isSuccess, error) => this.value = value;
|
||||
|
||||
public TValue? Value => IsSuccess ? value! : default;
|
||||
|
||||
public static implicit operator Result<TValue>(TValue? value) => Create(value);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Result(bool IsSuccess, Error Error)
|
||||
{
|
||||
public bool IsFailure => !IsSuccess;
|
||||
|
||||
public static Result Success() => new(true, Error.None);
|
||||
|
||||
public static Result<TValue> Success<TValue>(TValue value) => new(value, true, Error.None);
|
||||
|
||||
public static Result Failure(Error error) => new(false, error);
|
||||
|
||||
public static Result<TValue> Failure<TValue>(Error error) => new(default, false, error);
|
||||
|
||||
public static Result Create(bool condition) => condition ? Success() : Failure(Error.ConditionNotMet);
|
||||
|
||||
public static Result<TValue> Create<TValue>(TValue? value) => value is not null ? Success(value) : Failure<TValue>(Error.Null);
|
||||
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class ValidationRule
|
||||
Message = "";
|
||||
}
|
||||
|
||||
public async Task<bool> ValidateAsync()
|
||||
public async Task<bool> Validate()
|
||||
{
|
||||
if (syncValidation is not null)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ public class Validator(string propertyName,
|
||||
{
|
||||
foreach (ValidationRule rule in rules)
|
||||
{
|
||||
if (!await rule.ValidateAsync())
|
||||
if (!await rule.Validate())
|
||||
{
|
||||
return (false, rule.Message);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Toolkit.UI.Controls.Avalonia;
|
||||
|
||||
public class InfoBar :
|
||||
FluentAvalonia.UI.Controls.InfoBar
|
||||
{
|
||||
protected override Type StyleKeyOverride =>
|
||||
typeof(FluentAvalonia.UI.Controls.InfoBar);
|
||||
}
|
||||
Reference in New Issue
Block a user