@@ -145,31 +145,17 @@ public ICollection<string> GetAncestors(string componentId)
145145 public HashSet < TypedComponent > GetAncestorsAsTypedComponents ( string componentId , Func < string , TypedComponent > toTypedComponent )
146146 {
147147 ArgumentNullException . ThrowIfNull ( componentId ) ;
148- var ancestorSet = new HashSet < TypedComponent > ( new ComponentComparer ( ) ) ;
149- var ancestors = this . GetAncestors ( componentId ) ;
150- foreach ( var ancestor in ancestors )
151- {
152- var component = this . componentNodes [ ancestor ] ;
153- component . TypedComponent ??= toTypedComponent ( ancestor ) ;
154- ancestorSet . Add ( component . TypedComponent ) ;
155- }
156-
157- return ancestorSet ;
148+ return this . GetAncestors ( componentId )
149+ . Select ( a => this . componentNodes [ a ] . TypedComponent ?? toTypedComponent ( a ) )
150+ . ToHashSet ( new ComponentComparer ( ) ) ;
158151 }
159152
160153 public HashSet < TypedComponent > GetRootsAsTypedComponents ( string componentId , Func < string , TypedComponent > toTypedComponent )
161154 {
162155 ArgumentNullException . ThrowIfNull ( componentId ) ;
163- var rootSet = new HashSet < TypedComponent > ( new ComponentComparer ( ) ) ;
164- var roots = this . GetExplicitReferencedDependencyIds ( componentId ) ;
165- foreach ( var root in roots )
166- {
167- var component = this . componentNodes [ root ] ;
168- component . TypedComponent ??= toTypedComponent ( root ) ;
169- rootSet . Add ( component . TypedComponent ) ;
170- }
171-
172- return rootSet ;
156+ return this . GetExplicitReferencedDependencyIds ( componentId )
157+ . Select ( r => this . componentNodes [ r ] . TypedComponent ?? toTypedComponent ( r ) )
158+ . ToHashSet ( new ComponentComparer ( ) ) ;
173159 }
174160
175161 public void FillTypedComponents ( Func < string , TypedComponent > toTypedComponent )
0 commit comments