internal ElementWrapper(GumboElementNode node, NodeWrapper parent, WrapperFactory factory) : base(node, parent) { _Children = factory.CreateDisposalAwareLazy(() => ImmutableArray.CreateRange(node.GetChildren().OrderBy(x => x.index_within_parent).Select(x => factory.CreateNodeWrapper(x, this)))); _Attributes = factory.CreateDisposalAwareLazy(() => ImmutableArray.CreateRange(node.GetAttributes().Select(x => factory.CreateAttributeWrapper(x, this)))); _Value = factory.CreateDisposalAwareLazy(() => string.Concat(Children.Select(x => x is ElementWrapper ? ((ElementWrapper)x).Value : ((TextWrapper)x).Value))); StartPosition = node.element.start_pos; EndPosition = node.element.end_pos; Tag = node.element.tag; TagNamespace = node.element.tag_namespace; OriginalTag = NativeUtf8Helper.StringFromNativeUtf8( node.element.original_tag.data, (int)node.element.original_tag.length); OriginalTagName = GetTagNameFromOriginalTag(node.element); OriginalEndTag = NativeUtf8Helper.StringFromNativeUtf8( node.element.original_end_tag.data, (int)node.element.original_end_tag.length); NormalizedTagName = NativeUtf8Helper.StringFromNativeUtf8( NativeMethods.gumbo_normalized_tagname(node.element.tag)); }
internal ElementWrapper(GumboElementNode node, NodeWrapper parent, DisposalAwareLazyFactory lazyFactory, Action <string, ElementWrapper> addElementWithId) : base(node, parent) { _Children = lazyFactory.Create <IEnumerable <NodeWrapper> >(() => { return(node.GetChildren().Select(x => x is GumboElementNode ? (NodeWrapper) new ElementWrapper((GumboElementNode)x, this, lazyFactory, addElementWithId) : (NodeWrapper) new TextWrapper((GumboTextNode)x, this)).ToList().AsReadOnly()); }); _Attributes = lazyFactory.Create <IEnumerable <AttributeWrapper> >(() => { return(node.GetAttributes().Select((x, i) => new AttributeWrapper(x, this, i, addElementWithId)).ToList()); }); _Value = lazyFactory.Create <string>(() => { return(String.Concat(this.Children.Select(x => x is ElementWrapper ? ((ElementWrapper)x).Value : ((TextWrapper)x).Text))); }); StartPosition = node.element.start_pos; EndPosition = node.element.end_pos; Tag = node.element.tag; TagNamespace = node.element.tag_namespace; OriginalTag = NativeUtf8Helper.StringFromNativeUtf8( node.element.original_tag.data, (int)node.element.original_tag.length); OriginalTagName = GetTagNameFromOriginalTag(node.element); OriginalEndTag = NativeUtf8Helper.StringFromNativeUtf8( node.element.original_end_tag.data, (int)node.element.original_end_tag.length); NormalizedTagName = NativeUtf8Helper.StringFromNativeUtf8( NativeMethods.gumbo_normalized_tagname(node.element.tag)); }