Skip to content

Марченко Максим#238

Open
maks-march wants to merge 3 commits intokontur-courses:masterfrom
maks-march:homework
Open

Марченко Максим#238
maks-march wants to merge 3 commits intokontur-courses:masterfrom
maks-march:homework

Conversation

@maks-march
Copy link
Copy Markdown

Наставник: @Zuguki
Реализовал минимальные требования, пока не понял как сделать рабочий функционал для словарей и коллекций.

{
public static class ObjectExtensions
{
public static string PrintToString<T>(this T obj)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется не совсем удачное название, так как ты просто возвращаешь строку и не понятно почему Print. Предлагаю либо указывать что мы преобразуем в строку (но тогда по сути достаточно ToString() переопределить), либо сделать действительно Print, который будет печатать в консоль


private readonly Dictionary<Type, Func<object, string>> _typeSerializers;
private readonly Dictionary<string, Func<TOwner, string>> _propertySerializers;
private readonly HashSet<(string name, object current, object parent)> _printedObjects = [];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, что лучше тут создать record и складывать его в hashset


public PrintingConfig<TOwner> Excluding<TPropType>()
{
var excludedTypes = new HashSet<Type>(_excludedTypes)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем мы тут пересоздаем hashset?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для иммутабельности PrintingConfig

_propertySerializers = propertySerializers ?? new Dictionary<string, Func<TOwner, string>>();
}

public PrintingConfig<TOwner> BuildPrintingConfig(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Смотри, у тебя +- в каждом методе вызывается BuildPrintingConfig. При этом он публичный. Точно ли он должен быть доступным извне?

Вообще если делать что то вроде билдера, то в билдерах обычно в конце вызывается метод Build

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private не получится так, как он используется в PropertyPrintingConfig, можно internal и он будет CopyWithChanges, он просто копию возвращает с заменой полей

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants