You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/src/Recyclarr.Cli/Console/Helpers/FileInfoConverter.cs

33 lines
754 B

using System.ComponentModel;
using System.Globalization;
using System.IO.Abstractions;
namespace Recyclarr.Cli.Console.Helpers;
internal class FileInfoConverter : TypeConverter
{
private readonly IFileSystem _fs;
public FileInfoConverter(IFileSystem fs)
{
_fs = fs;
}
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
// ReSharper disable once InvertIf
if (value is string path)
{
var info = _fs.FileInfo.New(path);
if (!info.Exists)
{
throw new FileNotFoundException("The file does not exist", path);
}
return info;
}
return null;
}
}