private static ICargo Map(CargoDto c) { ICargo result; if (c.Type == "FreshWater") { result = new FreshWaterClientSideEntity { Type = c.Type, Guid = c.Guid } } ; else if (c.Type == "Salt") { result = new SaltClientSideEntity { Type = c.Type, Guid = c.Guid } } ; else if (c.Type == "SaltWater") { result = new FreshWaterClientSideEntity { Type = c.Type, Guid = c.Guid } } ; else { throw new Exception($"Unexpected cargo type='{c.Type}'"); } result.Count = c.Count; return(result); }
public T GetNewInstance <T>(string type) where T : class, IEntityBase { T result = null; type = H.Get(type); if (type == H.Get <IWorld>()) { var cc = new WorldClientSideEntity(); WorldRepository.Add(cc); result = cc as T; } else if (type == H.Get <IPlayer>()) { var cc = new PlayerClientSideEntity(); result = cc as T; } else if (type == H.Get <ICity>()) { var cc = new CityClientSideEntity(); result = cc as T; } else if (type == H.Get <IBramin>()) { var cc = new BraminClientSideEntity(); result = cc as T; } else if (type == H.Get <ILivingHouse>()) { var cc = new LivingHouseClientSideEntity(); result = cc as T; } else if (type == H.Get <ISaltEvaporationFactory>()) { var cc = new SaltEvaporationFactoryClientSideEntity(); result = cc as T; } else if (type == H.Get <IFreshWater>()) { var cc = new FreshWaterClientSideEntity(); result = cc as T; } else if (type == H.Get <ISaltWater>()) { var cc = new SaltWaterClientSideEntity(); result = cc as T; } else if (type == H.Get <ISalt>()) { var cc = new SaltClientSideEntity(); result = cc as T; } else { throw new Exception($"Unexpected type='{type}'"); } if (result == null) { throw new Exception($"Can't cast '{type}' to {typeof(T).Name}"); } return(result); }