Skip to content

Тимур Бабаев#248

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

Тимур Бабаев#248
truefolder wants to merge 3 commits intokontur-courses:masterfrom
truefolder:homework

Conversation

@truefolder
Copy link
Copy Markdown

No description provided.

Comment on lines +8 to +9
public class ObjectPrinterTests
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не увидел, хотя бы одного теста на то а как в целом организована структура сереализированного объекта, например вот такая строка подойдет под условия первого теста

Name = AlexAge = 19Height = 190,5 и т.д

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.

Добавил тест проверяющий отступы/новые линии на первых нескольких свойствах

Comment thread ObjectPrinting/Solved/PrintingConfig.cs Outdated
Comment on lines +119 to +120
private bool TryProcessDictionary(object? obj, Type type, string indentation,
int nestingLevel, out string? result)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Зачем тут ответы превращаем в строку, кажется эффективней было бы StringBuilder отдавать

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.

Ну вообще на выходе из метода там где он вернет true мы все равно каждый раз будем вызывать sb.ToString(), но касательно конкатенации строк да, согласен, так будет эффективнее

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.

Поправил, теперь создаю единственный экземпляр StringBuilder'а в PrintToString, и переиспользую его в каждом методе. Избавился от out параметров таким образом


namespace ObjectPrinting.Solved
namespace ObjectPrinting.Solved;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

У тебя сейчас конфиг отвечает за подготовку конфиги, и за то как его потом пременять, давай разведем эту штуку на два разных класса

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.

Поправил, разделил на 3 класса - на модель настроек, на конфигуратор с публичными методами и на принтер, который отвечает за сбор всех объектов и их печать

Comment on lines +19 to +22
public PrintingConfig<TOwner> Using(CultureInfo culture)
{
PrintingConfig<TOwner> ParentConfig { get; }
if (memberInfo == null)
printingConfig.AddTypeCulture<TPropType>(culture);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А для всех полей можно использовать культуру?

Copy link
Copy Markdown
Author

@truefolder truefolder Nov 20, 2025

Choose a reason for hiding this comment

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

https://learn.microsoft.com/ru-ru/dotnet/api/system.iformattable?view=net-9.0
Почти да, ну для всего что наследуется от IFormattable, строка как минимум не в их числе, поправлю

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.

Поправил

Comment on lines +327 to +329
var result = ObjectPrinter.For<Person>()
.Printing(m => m.Pets).Using(s => string.Join(" ", s).Replace("1", "2"))
.PrintToString(person);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А зачем здесь Replace?

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.

Просто ради теста

Comment on lines +335 to +342
public void PrintToString_ShouldSerializeDoubleWithCulture_WhenAllPropertiesAreSet()
{
var result = ObjectPrinter.For<Person>()
.Printing(m => m.Height).Using(CultureInfo.InvariantCulture)
.PrintToString(person);

result.Should().Contain("Height = 190.5");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

тест не дает инфы о том что только на это поле использовалась культура

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.

Поправил, теперь проверяем другое форматируемое свойство на предмет неизменности культуры

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