Init
This commit is contained in:
53
Prefab.Base/LookupEntity.cs
Normal file
53
Prefab.Base/LookupEntity.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user