Files
riversong-code-showcase/Source/Riversong/Game/CommonServices/Entities/EntityCollectionExtensions.cs
2026-05-21 16:04:49 +02:00

23 lines
753 B
C#

namespace DanieleMarotta.RiversongCodeShowcase
{
public static class EntityCollectionExtensions
{
public static T Get<T>(this IEntityCollection entityCollection, int id) where T : Entity
{
return (T)entityCollection.Get(id);
}
public static T CreateAndAdd<T>(this IEntityCollection entityCollection) where T : Entity, new()
{
var entity = entityCollection.Create<T>();
entityCollection.Add(entity);
return entity;
}
public static bool TryGet<T>(this IEntityCollection entityCollection, int id, out T entity) where T : Entity
{
entity = entityCollection.Get(id) as T;
return entity != null;
}
}
}