Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Махлонов Дмитрий #207

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

maakhhh
Copy link

@maakhhh maakhhh commented Dec 7, 2024

No description provided.

private const int MAX_RECURSION = 1;
private int currentRecursion = 0;
internal readonly SerializeConfig<TOwner> config = new();
private HashSet<object> processedObjects = new(ReferenceEqualityComparer.Instance);

Choose a reason for hiding this comment

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

Можно сделать readonly )

return "null" + Environment.NewLine;

if (name != null && config.PropertySerializers.TryGetValue(name, out var serializer))
return serializer.DynamicInvoke(obj).ToString() + Environment.NewLine;
if (processedObjects.Contains(obj))

Choose a reason for hiding this comment

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

Не стоит выбрасывать логику currentRecursion++ > MAX_RECURSION, так как рисовать 1000 вложенных объектов - всё равно не очень хорошо

result = null;
if (name != null && Config.PropertySerializers.TryGetValue(name, out var serializer))
{
result = serializer.Invoke(obj) + Environment.NewLine;

Choose a reason for hiding this comment

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

Функции можно вызывать просто об скобок serializer(obj). Чуть проще становится читать код

private bool TryPrintFinalTypes(Type? type, string? name, object obj, out string? result)
{
result = null;
var finalTypes = new List<Type>

Choose a reason for hiding this comment

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

Можно вынести в константы класса

return sb.ToString();
}

private string PrintIDictionary(IDictionary obj, int nestingLevel)

Choose a reason for hiding this comment

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

Если брать простые значения, то получается не очень понятная структура. Но это больше просто на подумать, такое решение вполне жизнеспособно

    Key: youTube
	Value: 3
	Key: fabric
	Value: 15

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.

3 participants