-
Notifications
You must be signed in to change notification settings - Fork 244
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
base: master
Are you sure you want to change the base?
Махлонов Дмитрий #207
Conversation
...Printing/Tests/Cases/ObjectPrinterTests.ObjectPrinter_ProcessesRecursionCorrect.received.txt
Outdated
Show resolved
Hide resolved
private const int MAX_RECURSION = 1; | ||
private int currentRecursion = 0; | ||
internal readonly SerializeConfig<TOwner> config = new(); | ||
private HashSet<object> processedObjects = new(ReferenceEqualityComparer.Instance); |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
No description provided.