Conversation
…ion about serialization
…es that chosen and creates tree with those properties
…r string with all chosen serializations and returns it to ObjectPrinter.PrintToString()
…ogic, added it to PrintToString in PrintingConfig.cs, new logic completely implemented
| return printingConfig; | ||
| } | ||
|
|
||
| public PrintingConfig<TOwner> Use(IFormatProvider formatProvider) |
There was a problem hiding this comment.
Можно тоже ограничить применение по типу. Зачем мне культура для символа например?
|
|
||
| internal PropertyPrintingConfig(PrintingConfig<TOwner> parentConfig, Expression<Func<TOwner, TPropType>> selector) | ||
| { | ||
| printingConfig = parentConfig ?? throw new ArgumentNullException(nameof(parentConfig)); |
There was a problem hiding this comment.
Прям везде проверять на null можно, но не обязательно. Я бы склонялся к тому, что всё должны описывать сигнатуры. Если в сигнатуре поле !nulalble а кто-то прокидывает туда его - это на его совести(и ему же огребать в большинстве случаев)
| public static class PropertyPrintingConfigExtensions | ||
| { | ||
| public static PrintingConfig<TOwner> Trim<TOwner>( | ||
| this PropertyPrintingConfig<TOwner, string> config, |
There was a problem hiding this comment.
Почему нельзя обрезать все строки, а только конкретные пропы?
|
|
||
| namespace ObjectPrinting.PrintingHandlers.ApplyingSettings.Appliers; | ||
|
|
||
| internal class CultureApplier : ISettingsApplier |
There was a problem hiding this comment.
Обычно в названии имплементации пишут полное название интерфейса CultureSettingsApplier. Да и так просто понятнее, что делает этот класс. А то он просто "применитель"
| !context.Settings.StringTrimLengths.TryGetValue(context.Path, out var max)) | ||
| return ApplierResult.NotApplied; | ||
|
|
||
| var trimmed = s.Length <= max ? s : s[..max]; |
There was a problem hiding this comment.
Любые работы со строками дорогие. Как насчёт использовать Span?
| else if (printed.Contains(Environment.NewLine)) | ||
| { | ||
| sb.Append(prefix).Append($"[{i}] = ").AppendLine(); | ||
| var lines = printed.Split(["\r\n", "\n"], StringSplitOptions.None); |
There was a problem hiding this comment.
\r\n/\n
Это же всё равно зависит от Environment.NewLine. Я бы предложил оставить только его
| sb.Append(prefix).Append($"[{i}] = ").AppendLine(); | ||
| var lines = printed.Split(["\r\n", "\n"], StringSplitOptions.None); | ||
| foreach (var line in lines) | ||
| sb.Append(prefix).Append('\t').AppendLine(line); |
There was a problem hiding this comment.
Почему бы не добавлять prefix в самом printed? Чтобы Enumerable им сразу говорил что их Indent больше, тк они часть коллекции.
А то получаются какие-то лишние и неочевидные пересборки строк
| { | ||
| public bool CanHandle(ValueContext context) | ||
| { | ||
| switch (context.Value) |
There was a problem hiding this comment.
Почему не if (context.Value is null or string) return false? Такой switch тяжелее читать
|
|
||
| var type = context.Type; | ||
| if (type == null) return true; | ||
| if (type.IsPrimitive) return false; |
There was a problem hiding this comment.
логика проверки на Примитив используется уже в 2 местах. Можно вынести в helper/etc
| { | ||
| sb.Append(prefix).Append(p.Name).Append(" = ").AppendLine(); | ||
| var childIndent = new string('\t', context.Indent + 2); | ||
| var lines = printed.Split(["\r\n", "\n"], StringSplitOptions.None); |
…rity than trim of string property
…lt serialize doesnt break it)
@FnaTikJK