예제 #1
0
        public MonsterFactory(IRepository repository)
        {
            if (repository == null)
            {
                throw new ArgumentNullException("A monster repository must be supplied");
            }

            this.monsterCollection = repository.GetMonsterCollection();
            Count = monsterCollection.Monsters.Count;
        }
예제 #2
0
        public MonsterCollection GetMonsterCollection()
        {
            var fileName     = ConfigurationManager.AppSettings["MonsterFileName"];
            var monsterModel = new MonsterCollection();

            try
            {
                var monsterData = File.ReadAllText(fileName);
                monsterModel = JsonConvert.DeserializeObject <MonsterCollection>(monsterData);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error occured while trying to load {fileName}. Exception details : {ex}");
            }

            return(monsterModel);
        }