Skip to content

Голубев Владимир#249

Open
tazik23 wants to merge 43 commits intokontur-courses:masterfrom
tazik23:master
Open

Голубев Владимир#249
tazik23 wants to merge 43 commits intokontur-courses:masterfrom
tazik23:master

Conversation

@tazik23
Copy link
Copy Markdown

@tazik23 tazik23 commented Nov 20, 2025

@tazik23 tazik23 changed the title @dmrz1n Голубев Владимир Nov 20, 2025

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.

А тебе название PrintToString не кажется странным? Мб просто Print эти экстеншоны назовём?

this TypePrintingConfig<TOwner, TProp> config, CultureInfo cultureInfo)
where TProp : IFormattable
{
config.Config.TypeCultures[typeof(TProp)] = cultureInfo;
Copy link
Copy Markdown

@Dimques Dimques Nov 20, 2025

Choose a reason for hiding this comment

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

Не нравится, что напрямую во внутрянку конфига лезешь, что-то там изменяешь и вообще что знаешь, как там и что делать ("возьму тип Prop, он будет ключом словаря, по этому ключу положу cultureInfo"). Мб сделаем методы, которые будут этим заниматься и просто снаружи будем их дёргать?
Бтв, я видел, что коллекции вложенного конфига имеют модификатор internal, дак вот если ты имел ввиду, что снаружи твоей либы интернал-членами никто не сможет воспользоваться, то остаются такие недостатки:

  1. все, кто используют Config, становятся зависимыми от знаний о его внутренней реализации (то, что там дефолтный словарь, который умеет в оператор []) - если ты его заменишь на что-нибудь другое, придётся во всех похожих местах поменять код соответственно
  2. другим разработчикам вряд ли захочется помнить обо всех особенностях добавления культуры в твой класс, им захочется иметь простой интерфейс, чтобы вызвать его и забыть

return string.Empty;
}

if (!type.IsValueType)

This comment was marked as resolved.

This comment was marked as resolved.

private string PrintToString(object? obj, int nestingLevel, HashSet<object> visited)
{
if (nestingLevel > maxRecursionDepth)
{

This comment was marked as resolved.

return PrintObject(obj, nestingLevel, visited);
}

private string PrintObject(object obj, int nestingLevel, HashSet<object> visited)

This comment was marked as resolved.


public partial class ObjectPrintingTests
{
public partial class CollectionTests

This comment was marked as resolved.


var result = printer.PrintToString(data);

result.Should()

This comment was marked as resolved.

var printer = ObjectPrinter.For<Dictionary<CollectionTestsClass, Department>>();
var result = printer.PrintToString(dict);

result.Should().MatchRegex(

This comment was marked as resolved.



[Test]
public void PrintToString_ExcludedType_ShouldNotSerializeMembersOfThatType()

This comment was marked as resolved.

{
var dict = new Dictionary<CollectionTestsClass, Department>
{
[new CollectionTestsClass { Name = "Manager" }] = new Department { Name = "HR" },

This comment was marked as resolved.

}

[Test]
public void TrimToLength_NotPositiveValue_ShouldThrowArgumentException()

This comment was marked as resolved.


namespace Tests.Tests;

public partial class ObjectPrintingTests

This comment was marked as resolved.

.And.NotContain("level16");
}

[TestCase(0)]

This comment was marked as resolved.


var result = printer.PrintToString(testData);

await Verify(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.

Эти тестики тоже падают. Эта штука пытается сравнивать какие-то файлы, которые сама создаёт, один из них пустой . А ещё она пытается процес с visual studio запустить.

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