-
Notifications
You must be signed in to change notification settings - Fork 245
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
base: master
Are you sure you want to change the base?
Conversation
ITypePrintConfig<TOwner, TType> For<TType>(); | ||
|
||
IFieldPrintConfig<TOwner, TField> For<TField>(Expression<Func<TOwner, TField>> selectMember); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
var indentation = CreateIndentation(nestingLevel); | ||
stringBuilder.AppendLine(string.Concat(indentation, "Collection")); | ||
nestingLevel++; | ||
indentation = CreateIndentation(nestingLevel); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
{ | ||
return propertyInfo.PropertyType; | ||
} | ||
else if (member is FieldInfo fieldInfo) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
.Where(m => m is FieldInfo || m is PropertyInfo); | ||
} | ||
|
||
private string TrimToLength(string str, uint len) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
if (len == 0) return string.Empty; | ||
if (str.Length <= len) return str; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
return new string('\t', nestingLevel); | ||
} | ||
|
||
private HashSet<Type> numericTypes = new HashSet<Type>() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
//cycles | ||
if(processedObjects.Contains(obj)) | ||
return String.Empty; | ||
|
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
return obj switch | ||
{ | ||
IDictionary dictionary => PrintDictionary(dictionary, nestingLevel), | ||
ICollection collection => PrintCollection(collection, nestingLevel), |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
var valuePrint = PrintToString(value, nestingLevel - 1); | ||
|
||
stringBuilder.AppendLine(valuePrint.TrimStart('\t')); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
private HashSet<Type> finalTypes = new() | ||
{ | ||
typeof(int), typeof(double), typeof(float), typeof(string), | ||
typeof(DateTime), typeof(TimeSpan), typeof(Guid) | ||
}; |
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.
Это далеко не все типы, которые можно сериализовать простым ToString. Есть bool, char, long
Есть ещё енумы, которые клиент может сам создать. Я вот например создам enum BookGenre
, где будут Фэнтези, Романтика, Экшн, Детектив итд, затолкаю в принтер и не увижу ничего хорошего
Можешь покопаться в данных типа Type
и найдёшь там поле, которое однозначно говорит, можно ли заданный тип сериализовать через ToString
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.
Я нашел поле IsSerializable, но я думаю его нельзя здесь использовать. Поэтому я для проверки того что тип "конечный" использовал проверки на Type.IsPrimitive и Type.IsEnum вместе с проверкой дополнительных прописанных мной типов таких как: DateTime, TimeSpan, Guid, string
@Inree, код по заданию домашней работы в ObjectSerializer и ObjectSerializerTests