feat: Add FindComponent on IElement (#153) #1738
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
FindComponent<TComponent>
This PR allows users to call
FindComponent
on anIElement
1. Fixes #153It should cover all the basic scenarios (see tests), even when using
ElementReferences
(that should stay valid when usingFindComponent
).The idea is that we can hook into the
CssSelectorElementFactory
(or the any other factory that inherits from IElementWrapperFactory or better the newIComponentAccessor
) to retrieve the elements rendered. If that way doesn't work, we use theBunitRenderer
and basically go through everything there (more expensive, but we could also solely rely on that).The last one happens if we have a
ParentComponent
that gets rendered, but we do acut.Find("...").FindComponent<ChildComponent>
.Considerations
The API forces the user to specify the desired output component type:
FindComponent<TComponent>
- we could also offer a version, where it "just" takes the direct parent component (as anIComponent
).1 It does not work in
INode
, so users can't use something like:cut.NodeList.First().FindComponent<TComponent>();
because I have no idea on how to hook into that pipeline. Maybe we some factories of Anglesharp, but I am not too deep into that at the moment.