void ClearViewAttributes(IModelMergedDifferenceStrategy strategy, IModelObjectView modelObjectView) { foreach (var valueInfo in GetValuesInfos(modelObjectView, strategy.MergedViewValueInfos)) { modelObjectView.ClearValue(valueInfo.Name); } }
void MergeObjectViewValueInfos(IModelMergedDifferenceStrategy differenceStrategy, IModelView sourceObjectView, IModelObjectView targetObjectView) { foreach (var valueInfo in GetValuesInfos(sourceObjectView, differenceStrategy.MergedViewValueInfos)) { var sourceValue = sourceObjectView.GetValue(valueInfo.Name, valueInfo.PropertyType); var targetValue = targetObjectView.GetValue(valueInfo.Name, valueInfo.PropertyType); if (sourceValue != targetValue) { targetObjectView.SetValue(valueInfo.Name, valueInfo.PropertyType, sourceValue); } } }
void RemoveStrategyUnrelatedNodes(IModelObjectView modelObjectView, IModelMergedDifferenceStrategy strategy) { var nodePaths = new HashSet <string>(GetIncludedNodePaths(modelObjectView, strategy).Select(path => path.NodePath)); for (int i = modelObjectView.NodeCount - 1; i >= 0; i--) { var modelNode = modelObjectView.GetNode(i); var id = modelNode.Id(); if (!nodePaths.Contains(id)) { modelNode.Remove(); } } }
IEnumerable <IModelMergedDifferenceStrategyIncludedNodePath> GetIncludedNodePaths(IModelObjectView modelObjectView, IModelMergedDifferenceStrategy strategy) { var viewType = modelObjectView is IModelDetailView ? ViewType.DetailView : ViewType.ListView; return(strategy.IncludedNodePaths.Where(path => path.ViewType == viewType || path.ViewType == ViewType.Any)); }