Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class EntityFactory
{
private Dictionary<EntityType, Func<entity>> _entityTypeMapper;
public EntityFactory()
{
_entityTypeMapper = new Dictionary<entitytype, func<entity="">>();
_entityTypeMapper.Add(EntityType.Type0, () => { return new Type0Entity(); });
_entityTypeMapper.Add(EntityType.Type1, () => { return new Type1Entity(); });
_entityTypeMapper.Add(EntityType.Type2, () => { return new Type2Entity(); });
}
public Entity GetEntityBasedOnType(EntityType entityType)
{
return _entityTypeMapper[entityType]();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment