Код: Выделить всё
internal static class ExceptionExtensions
{
extension(FileNotFoundException)
{
internal static void ThrowIfNullOrNotExist(string? fileName)
{
if (string.IsNullOrWhiteSpace(fileName) || !File.Exists(fileName))
{
throw new FileNotFoundException("File has not been found", fileName);
}
}
}
}
Код: Выделить всё
internal static void WriteFile(string? fileName)
{
FileNotFoundException.ThrowIfNullOrNotExist(fileName);
// Later...
using var fs = new FileStream(fileName, fso);
}
Здесь имя файла может быть нулевым.
Как запустить проверку на наличие значений NULL?>