public IPropBagMapperGen GetPropBagMapper(IPropBagMapperRequestKeyGen mapperRequest) { if (mapperRequest.AutoMapper == null) { throw new InvalidOperationException($"The {nameof(SimplePropBagMapperCache)} was asked to GetPropBagMapper, however the mapperRequest has a null AutoMapper."); } IPropBagMapperRequestKeyGen save = mapperRequest; if (_propBagMappers.TryGetValue(mapperRequest, out IPropBagMapperGen result)) { return(result); } else { //IPropBagMapperKeyGen newOrExistingRequest = _Requests.GetOrAdd(mapperRequest); //result = _propBagMappers.GetOrAdd(newOrExistingRequest); // Remove the request from the request que if present. _requests.TryRemoveValue(mapperRequest, out IPropBagMapperRequestKeyGen dummyExistingRequest); result = _propBagMappers.GetOrAdd(mapperRequest); CheckForChanges(save, mapperRequest, "GetOrAdd PropBagMapper."); } return(result); }
private int SealThis(int cntr) { System.Diagnostics.Debug.WriteLine($"Creating Profile_{cntr.ToString()}"); int result = 0; foreach (IAutoMapperRequestKeyGen key in _unSealedAutoMappers.Keys) { IMapper mapper = _sealedAutoMappers.GetOrAdd(key); //key.AutoMapper = mapper; if (!(_unSealedAutoMappers.TryRemoveValue(key, out IAutoMapperRequestKeyGen dummyKey))) { System.Diagnostics.Debug.WriteLine("Couldn't remove mappper request from list of registered, pending to be created, mapper requests."); } result++; } return(result); }