Билдер для сущностей, что б красивее отображались
This commit is contained in:
@@ -16,15 +16,6 @@ public class EntitySerializer
|
||||
public List<FieldGroup> Groups { get; set; } = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Группа полей.
|
||||
/// </summary>
|
||||
public class FieldGroup
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public List<FieldInfo> Fields { get; set; } = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Информация о поле.
|
||||
/// </summary>
|
||||
@@ -49,21 +40,21 @@ public class EntitySerializer
|
||||
{
|
||||
SerializationResult result = new();
|
||||
|
||||
// Группа для основных полей Entity
|
||||
FieldGroup entityGroup = new() { Name = "Основные поля" };
|
||||
AddFieldsToGroup(entityGroup, fullEntity.Entity);
|
||||
result.Groups.Add(entityGroup);
|
||||
//// Группа для основных полей Entity
|
||||
//FieldGroup entityGroup = new() { Name = "Основные поля" };
|
||||
//AddFieldsToGroup(entityGroup, fullEntity.Entity);
|
||||
//result.Groups.Add(entityGroup);
|
||||
|
||||
// Группа для полей IEntity (SubEntity)
|
||||
if (fullEntity.SubEntity != null)
|
||||
{
|
||||
FieldGroup subEntityGroup = new()
|
||||
{
|
||||
Name = "Поля " + fullEntity.SubEntity.GetType().Name,
|
||||
};
|
||||
AddFieldsToGroup(subEntityGroup, fullEntity.SubEntity);
|
||||
result.Groups.Add(subEntityGroup);
|
||||
}
|
||||
//// Группа для полей IEntity (SubEntity)
|
||||
//if (fullEntity.SubEntity != null)
|
||||
//{
|
||||
// FieldGroup subEntityGroup = new()
|
||||
// {
|
||||
// Name = "Поля " + fullEntity.SubEntity.GetType().Name,
|
||||
// };
|
||||
// AddFieldsToGroup(subEntityGroup, fullEntity.SubEntity);
|
||||
// result.Groups.Add(subEntityGroup);
|
||||
//}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -71,25 +62,25 @@ public class EntitySerializer
|
||||
/// <summary>
|
||||
/// Добавить поля объекта в группу.
|
||||
/// </summary>
|
||||
private void AddFieldsToGroup(FieldGroup group, object obj)
|
||||
{
|
||||
Type type = obj.GetType();
|
||||
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
//private void AddFieldsToGroup(FieldGroup group, object obj)
|
||||
//{
|
||||
// Type type = obj.GetType();
|
||||
// PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
foreach (PropertyInfo property in properties)
|
||||
{
|
||||
// Пропускаем навигационные свойства Entity
|
||||
if (property.Name == "Entity")
|
||||
continue;
|
||||
// foreach (PropertyInfo property in properties)
|
||||
// {
|
||||
// // Пропускаем навигационные свойства Entity
|
||||
// if (property.Name == "Entity")
|
||||
// continue;
|
||||
|
||||
object? value = property.GetValue(obj);
|
||||
FieldInfo fieldInfo = CreateFieldInfo(property, value);
|
||||
group.Fields.Add(fieldInfo);
|
||||
}
|
||||
}
|
||||
// object? value = property.GetValue(obj);
|
||||
// FieldBuilderDefinition fieldInfo = CreateFieldInfo(property, value);
|
||||
// group.Fields.Add(fieldInfo);
|
||||
// }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Создать FieldInfo для свойства.
|
||||
/// Создать FieldBuilderDefinition для свойства.
|
||||
/// </summary>
|
||||
/// <param name="property">Поле класса.</param>
|
||||
/// <param name="value">Значение поля.</param>
|
||||
|
||||
Reference in New Issue
Block a user