public Person CreateInstance(Observation observation) { string key = GetPersonKeyFor(observation); if (peopleCache.ContainsKey(key)) { return peopleCache[key]; } else { string country = observation.Country; string personId = observation.PersonId; Person person = new Person(country, personId); peopleCache[key] = person; return person; } }
private void Validate(Observation o, int index) { if (string.IsNullOrWhiteSpace(o.Country)) { string errorMessage = string.Format("line ({0}): Country is missing", index); AddError(errorMessage); } if (string.IsNullOrWhiteSpace(o.PersonId)) { string errorMessage = string.Format("line ({0}): PersonId is missing", index); AddError(errorMessage); } }
private string GetPersonKeyFor(Observation observation) { return string.Format("{0}_{1}", observation.PersonId, observation.Country); }