Документирование и небольшой рефакторинг модели.

This commit is contained in:
2025-05-11 00:31:15 +04:00
parent 1a977ee988
commit 3c65274b45
64 changed files with 1960 additions and 554 deletions
+20 -3
View File
@@ -1,15 +1,30 @@
using System.Reflection;
using System.ComponentModel;
using System.Reflection;
using Pf2eModel.Model;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
namespace Pf2eModel;
/// <summary>
/// Аттрибут, указывающий тип сущности.
/// </summary>
/// <param name="type">Тип сущности.</param>
[AttributeUsage(AttributeTargets.Class)]
public class EntityOfTypeAttribute(EntityType type) : Attribute
{
/// <summary>
/// Тип сущности.
/// </summary>
public EntityType Type { get; } = type;
/// <summary>
/// Метод для получения программного типа сущности по её типу.
/// </summary>
/// <param name="entity">Тип сущности.</param>
/// <returns>Программный тип сущности.</returns>
/// <exception cref="Exception">Если есть ошибка в структурах.</exception>
/// <exception cref="InvalidEnumArgumentException">Тип сущности.</exception>
public static Type Resolve(Entity entity)
{
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
@@ -21,7 +36,7 @@ public class EntityOfTypeAttribute(EntityType type) : Attribute
if (!type.IsAssignableTo(typeof(IEntity)))
{
throw new Exception(
throw new(
$"'EntityOfTypeAttribute' attribute should only be applied to children of 'IEntity' class. '{type.FullName}' is not."
);
}
@@ -34,6 +49,8 @@ public class EntityOfTypeAttribute(EntityType type) : Attribute
}
}
throw new Exception($"Can't resolve class associated with '{entity.Type}' EntityType.");
throw new InvalidEnumArgumentException(
$"Can't resolve class associated with '{entity.Type}' EntityType."
);
}
}