private void MergeResource(List <IProp> result, Resource resource) { var removedResource = PropRemoved.OfType <Resource>() .SingleOrDefault(x => x.Scheme == resource.Scheme); var addedResource = PropAdded.OfType <Resource>() .SingleOrDefault(x => x.Scheme == resource.Scheme); var addedCount = addedResource?.Count; var removedCount = removedResource?.Count; var remainsCount = (resource.Count + addedCount.GetValueOrDefault()) - removedCount.GetValueOrDefault(); if (remainsCount > 0) { var remainsResource = new Resource(resource.Scheme, remainsCount); result.Add(remainsResource); } }
/// <summary> /// Предметы в хранилище. /// </summary> public IProp[] CalcActualItems() { var result = new List <IProp>(); var propStoreItems = PropStore.CalcActualItems(); foreach (var prop in propStoreItems) { switch (prop) { case Resource resource: var removedResource = PropRemoved.OfType <Resource>() .SingleOrDefault(x => x.Scheme == resource.Scheme); var addedResource = PropAdded.OfType <Resource>() .SingleOrDefault(x => x.Scheme == resource.Scheme); var addedCount = addedResource?.Count; var removedCount = removedResource?.Count; var remainsCount = resource.Count + addedCount.GetValueOrDefault() - removedCount.GetValueOrDefault(); if (remainsCount > 0) { var remainsResource = new Resource(resource.Scheme, remainsCount); result.Add(remainsResource); } break; case Equipment _: case Concept _: var isRemoved = PropRemoved.Contains(prop); if (!isRemoved) { result.Add(prop); } break; } } foreach (var prop in PropAdded) { switch (prop) { case Resource _: var existsResource = result.SingleOrDefault(x => x.Scheme == prop.Scheme); if (existsResource == null) { result.Add(prop); } break; case Equipment _: case Concept _: result.Add(prop); break; default: throw new NotSupportedException(); } } return(result.ToArray()); }