parent
39f106c72b
commit
29ca61f68f
@ -1,31 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Recyclarr.Common.Extensions;
|
||||
|
||||
public static class JsonNetExtensions
|
||||
{
|
||||
public static JEnumerable<T> Children<T>(this JToken token, string key)
|
||||
where T : JToken
|
||||
{
|
||||
return token[key]?.Children<T>() ?? JEnumerable<T>.Empty;
|
||||
}
|
||||
|
||||
public static T ValueOrThrow<T>(this JToken token, string key)
|
||||
where T : class
|
||||
{
|
||||
var value = token.Value<T>(key);
|
||||
if (value is null)
|
||||
{
|
||||
throw new ArgumentNullException(token.Path);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static T Clone<T>(this T source) where T : notnull
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(source))
|
||||
?? throw new ArgumentException("Could not deep clone", nameof(source));
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace Recyclarr.Common.FluentValidation;
|
||||
|
||||
public interface IValidatorFactory
|
||||
{
|
||||
IValidator GetValidator(Type typeToValidate);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
using Autofac;
|
||||
using FluentValidation;
|
||||
using Recyclarr.Common.Extensions;
|
||||
|
||||
namespace Recyclarr.Common.FluentValidation;
|
||||
|
||||
public class ValidatorFactory : IValidatorFactory
|
||||
{
|
||||
private readonly ILifetimeScope _scope;
|
||||
|
||||
public ValidatorFactory(ILifetimeScope scope)
|
||||
{
|
||||
_scope = scope;
|
||||
}
|
||||
|
||||
public IValidator GetValidator(Type typeToValidate)
|
||||
{
|
||||
return (IValidator) _scope.ResolveGeneric(typeof(IValidator<>), typeToValidate);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue