public HashSet <PropertyInfoVertex> GetOrBuildPaths(IEnumerable <Type> sourceTypes, Type searchType, PathBuilderSearchCache cache) { var propertyPathsSet = new HashSet <PropertyInfoVertex>(); var searchVertex = _typeGraph.GetTypeVertex(searchType); foreach (var sourceType in sourceTypes) { var sourceVertex = _typeGraph.GetTypeVertex(sourceType); if (cache.AllVertices.ContainsKey(sourceVertex)) { propertyPathsSet.UnionWith(cache.AllVertices[sourceVertex]); continue; } if (!_typeGraph.PathExists(sourceVertex, searchVertex)) { continue; } var properties = BuildSearchTree(sourceVertex, searchVertex, cache); if (properties.Count == 0) { throw new InvalidOperationException("Не найден ни один путь"); } propertyPathsSet.UnionWith(properties); } if (propertyPathsSet.Count == 0) { throw new InvalidOperationException("Не найден ни один путь"); } foreach (var node in propertyPathsSet) { node.IsRoot = true; } var hierarchyTypes = SearchHelper <TBaseSearchInterface> .FindHierarchy(searchType); foreach (var type in hierarchyTypes) { var typeVertex = _typeGraph.GetTypeVertex(type); HashSet <PropertyInfoVertex> edges; if (!cache.AllVertices.TryGetValue(typeVertex, out edges)) { continue; } foreach (var parent in edges.SelectMany(edge => edge.Parents)) { parent.IsFinal = true; } } return(propertyPathsSet); }