54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
namespace Prefab.Base;
|
|
|
|
/// <summary>
|
|
/// Represents a lookup entity that can be used to represent a PrefabEnum in a database table.
|
|
/// </summary>
|
|
/// <typeparam name="TEnum">The type that will represent the entity's backed <see cref="PrefabEnum" /> type.</typeparam>
|
|
public abstract class LookupEntity<TEnum> : ISortOrder where TEnum : PrefabEnum<TEnum>
|
|
{
|
|
/// <summary>
|
|
/// The underlying integer value of the enum.
|
|
/// </summary>
|
|
public int Id { get; set; } // This will match the PrefabEnum's underlying int value
|
|
|
|
/// <summary>
|
|
/// The name of the enum member (e.g., "Pending").
|
|
/// </summary>
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// The short name of the enum member (e.g., "Pend").
|
|
/// </summary>
|
|
public string? ShortName { get; set; }
|
|
|
|
/// <summary>
|
|
/// An optional description of the enum member.
|
|
/// </summary>
|
|
public string? Description { get; set; }
|
|
|
|
/// <inheritdoc />
|
|
public int SortOrder { get; set; }
|
|
|
|
/// <summary>
|
|
/// Default constructor.
|
|
/// </summary>
|
|
protected LookupEntity() { }
|
|
|
|
/// <summary>
|
|
/// Constructor to create from a PrefabEnum instance.
|
|
/// </summary>
|
|
protected LookupEntity(TEnum prefabEnum)
|
|
{
|
|
Id = prefabEnum.Value;
|
|
Name = prefabEnum.Name;
|
|
ShortName = null; // Set as needed
|
|
Description = null; // Set as needed
|
|
SortOrder = prefabEnum.Value; // Or set as needed
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all PrefabEnum instances for this type.
|
|
/// </summary>
|
|
public static IReadOnlyList<TEnum> GetAllEnumInstances() => PrefabEnum<TEnum>.List;
|
|
}
|