Conversation
| => IsSuccess ? func(Value) : Result<TResult>.Fail(Error); | ||
|
|
||
| public Result<TResult> Map<TResult>(Func<T, TResult> func) | ||
| => IsSuccess ? Result<TResult>.Ok(func(Value)) : Result<TResult>.Fail(Error); |
There was a problem hiding this comment.
В случае ошибки ты можешь вернуть this вместо создания нового объекта Result с той же ошибкой
|
|
||
| private Result<Size> CalculateRequiredImageSize(IReadOnlyList<CloudElement> elements, int padding) | ||
| { | ||
| if (padding < 0 || padding > 1000) |
| private Result<Size> CalculateRequiredImageSize(IReadOnlyList<CloudElement> elements, int padding) | ||
| { | ||
| if (padding < 0 || padding > 1000) | ||
| return Result<Size>.Fail("Invalid padding value"); |
There was a problem hiding this comment.
Здесь бы указать валидный диапазон для padding
| } | ||
| } | ||
|
|
||
| public Result SaveToFile( |
There was a problem hiding this comment.
Этот метод используется только в тестах. И уже есть IImageSaver
| { | ||
| public Result Save(Bitmap bitmap, string filePath) | ||
| { | ||
| if (bitmap == null) |
There was a problem hiding this comment.
В проекте включен Nullable enable, то есть если вопросика после Bitmap нет, то сюда и не придёт null. Ну точнее придёт только, если смелый разраб вызовет метод с bitmap!, но тогда null будет на его совести
Короче разрабы дотнета сделали нам nullable enable чтобы не приходилось проверять параметры на null
|
|
||
| OpenFile(settings.OutputFile); | ||
| } | ||
| private static void OpenDirectory(string path) |
| private static void OpenFile(string path) | ||
| { | ||
|
|
||
| Process.Start(new ProcessStartInfo |
| } | ||
|
|
||
|
|
||
| private static string[] GetDefaultEnglishStopWords() |
There was a problem hiding this comment.
Это бы вообще отсюда убрать в StopWordsFilter
Можно создать там статическое поле вместо метода
| public Result<string> Normalize(string word) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(word) || word.Length < WordsSettings.MinWordLength) | ||
| return Result<string>.Ok(string.Empty); |
| return this; | ||
| } | ||
|
|
||
| public Result Generate() |
There was a problem hiding this comment.
Тут бы накинуть [SupportedOSPlatform("windows")]
| var settings = ui.Run(); | ||
|
|
||
|
|
||
| if (!settings.IsSuccess) return; |
There was a problem hiding this comment.
Лучше назвать settingsResult. А то эта переменная ж хранит не настройки, а результат их получения
| } | ||
|
|
||
| OpenFile(settings.OutputFile); | ||
| OpenFile(settings.Value.OutputFile); |
There was a problem hiding this comment.
2 раза value достаётся, можно вынести в переменную
| var bitmap = new Bitmap(imageSize.Width, imageSize.Height); | ||
| Graphics g = null; | ||
|
|
||
| try |
There was a problem hiding this comment.
тут можно написать using (var g = Graphics.FromImage(bitmap)) { /*code*/ }
| return Result<Size>.Ok(new Size( | ||
| Math.Max(maxX + padding, 400), | ||
| Math.Max(maxY + padding, 200))); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| return Result<Size>.Fail($"Failed to calculate image size: {ex.Message}"); | ||
| } |
There was a problem hiding this comment.
здесь непонятно зачем try catch. Не вижу ситуации, в которой может вылететь exception
| return Result<List<CloudElement>>.Ok(shifted); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| return Result<List<CloudElement>>.Fail($"Failed to shift elements: {ex.Message}"); | ||
| } |
There was a problem hiding this comment.
Здесь тоже вроде не должен exception падать никогда
| private readonly LayoutSettings layoutSettings; | ||
| private readonly VisualizationSettings visualizationSettings; | ||
|
|
||
| private string inputFile; |
There was a problem hiding this comment.
райдер говорит, что inputFile должен быть nullable, тк в конструкторе он не инициализируется, и на момент использования может быть не задан
@Inree