private void AddIdNameCacheByCrossType(CrossReferenceType type) { Func <IEnumerable <Tuple <long, string> > > dataGetter; switch (type) { case CrossReferenceType.VisualDictionary: dataGetter = () => { List <RepresentationForUser> areas = _representationsQuery.GetVisibleWithoutAreas(); return(areas.Select(e => new Tuple <long, string>(e.Id, e.Title))); }; break; case CrossReferenceType.GroupWord: dataGetter = () => GetGroupsByType(GroupType.ByWord); break; case CrossReferenceType.GroupSentence: dataGetter = () => GetGroupsByType(GroupType.BySentence); break; default: throw new ArgumentException("Неизвестный тип " + type); } var idNameCache = new IdNameCache(dataGetter); _cachesByCrossReferenceTypes.Add(type, idNameCache); }
private string GetNameById(long id, CrossReferenceType type) { IdNameCache idNameCache = GetCacheByCrossType(type); return(idNameCache != null?idNameCache.GetName(id) : null); }
private long GetIdByName(string name, CrossReferenceType type) { IdNameCache idNameCache = GetCacheByCrossType(type); return(idNameCache != null?idNameCache.GetId(name) : IdValidator.INVALID_ID); }