Программа просмотра базы данных

This commit is contained in:
2025-04-18 17:26:52 +04:00
parent 372e41e51a
commit 9a711c5a9d
27 changed files with 701 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
using Pf2eModel.Model.Base;
using Pf2eModel.Model;
using Pf2eModel.Model.Enum;
using System.Reflection;
namespace Pf2eModel;
[AttributeUsage(AttributeTargets.Class)]
public class EntityOfTypeAttribute(EntityType type) : Attribute
{
public EntityType Type { get; } = type;
public static Type Resolve(Entity entity)
{
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
{
if (type.GetCustomAttributes(typeof(EntityOfTypeAttribute), true).Length <= 0)
{
continue;
}
if (!type.IsAssignableTo(typeof(IEntity)))
{
throw new Exception($"'EntityOfTypeAttribute' attribute should only be applied to children of 'IEntity' class. '{type.FullName}' is not.");
}
EntityOfTypeAttribute attribute = type.GetCustomAttribute<EntityOfTypeAttribute>()!;
if (attribute.Type == entity.Type)
{
return type;
}
}
throw new Exception($"Can't resolve class associated with '{entity.Type}' EntityType.");
}
}