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

Брайденбихер Виктор Николаевич #232

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

Conversation

viteokB
Copy link

@viteokB viteokB commented Dec 12, 2024

@Inree, код по заданию домашней работы в ObjectSerializer и ObjectSerializerTests

Comment on lines 7 to 9
ITypePrintConfig<TOwner, TType> For<TType>();

IFieldPrintConfig<TOwner, TField> For<TField>(Expression<Func<TOwner, TField>> selectMember);

This comment was marked as resolved.

var indentation = CreateIndentation(nestingLevel);
stringBuilder.AppendLine(string.Concat(indentation, "Collection"));
nestingLevel++;
indentation = CreateIndentation(nestingLevel);

This comment was marked as resolved.

{
return propertyInfo.PropertyType;
}
else if (member is FieldInfo fieldInfo)

This comment was marked as resolved.

.Where(m => m is FieldInfo || m is PropertyInfo);
}

private string TrimToLength(string str, uint len)

This comment was marked as resolved.

Comment on lines 278 to 279
if (len == 0) return string.Empty;
if (str.Length <= len) return str;

This comment was marked as resolved.

return new string('\t', nestingLevel);
}

private HashSet<Type> numericTypes = new HashSet<Type>()

This comment was marked as resolved.

Comment on lines 94 to 97
//cycles
if(processedObjects.Contains(obj))
return String.Empty;

This comment was marked as resolved.

return obj switch
{
IDictionary dictionary => PrintDictionary(dictionary, nestingLevel),
ICollection collection => PrintCollection(collection, nestingLevel),

This comment was marked as resolved.

Comment on lines 125 to 127
var valuePrint = PrintToString(value, nestingLevel - 1);

stringBuilder.AppendLine(valuePrint.TrimStart('\t'));

This comment was marked as resolved.

Comment on lines 31 to 35
private HashSet<Type> finalTypes = new()
{
typeof(int), typeof(double), typeof(float), typeof(string),
typeof(DateTime), typeof(TimeSpan), typeof(Guid)
};
Copy link

Choose a reason for hiding this comment

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

Это далеко не все типы, которые можно сериализовать простым ToString. Есть bool, char, long

Есть ещё енумы, которые клиент может сам создать. Я вот например создам enum BookGenre, где будут Фэнтези, Романтика, Экшн, Детектив итд, затолкаю в принтер и не увижу ничего хорошего

Можешь покопаться в данных типа Type и найдёшь там поле, которое однозначно говорит, можно ли заданный тип сериализовать через ToString

Copy link
Author

Choose a reason for hiding this comment

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

Я нашел поле IsSerializable, но я думаю его нельзя здесь использовать. Поэтому я для проверки того что тип "конечный" использовал проверки на Type.IsPrimitive и Type.IsEnum вместе с проверкой дополнительных прописанных мной типов таких как: DateTime, TimeSpan, Guid, string

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