public PackageGraph Build() { var nodes = new List <PackageGraphNode>(); foreach (var package in _packages) { var packageId = package.Key; var packageNode = nodes.FirstOrDefault(x => x.Package.IsSamePackage(packageId)); if (packageNode == null) { packageNode = new PackageGraphNode(packageId); nodes.Add(packageNode); } foreach (var dependencyId in package.Value) { var depPackageNode = nodes.FirstOrDefault(x => x.Package.IsSamePackage(dependencyId)); if (depPackageNode == null) { depPackageNode = new PackageGraphNode(dependencyId); nodes.Add(depPackageNode); } packageNode.AddDependency(depPackageNode); } } return(new PackageGraph(nodes.Where(x => x.Dependents.Count == 0).ToList(), nodes.Count)); }
public void AddDependency(PackageGraphNode dependency) { _dependencies.Add(dependency); dependency._dependents.Add(this); }