Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        internal DocumentWrapper(GumboDocumentNode node, DisposalAwareLazyFactory lazyFactory,
                                 Action <string, ElementWrapper> addElementWithId)
            : base(node, null)
        {
            _Children = lazyFactory.Create <IEnumerable <ElementWrapper> >(() =>
            {
                return(node.GetChildren().Select(x => new ElementWrapper((GumboElementNode)x, this,
                                                                         lazyFactory, addElementWithId)).ToList().AsReadOnly());
            });

            HasDocType        = node.document.has_doctype;
            Name              = NativeUtf8Helper.StringFromNativeUtf8(node.document.name);
            PublicIdentifier  = NativeUtf8Helper.StringFromNativeUtf8(node.document.public_identifier);
            SystemIdentifier  = NativeUtf8Helper.StringFromNativeUtf8(node.document.system_identifier);
            DocTypeQuirksMode = node.document.doc_type_quirks_mode;
        }
Exemplo n.º 3
0
 public Lazy <T> CreateDisposalAwareLazy <T>(Func <T> factoryMethod)
 {
     return(_LazyFactory.Create(factoryMethod));
 }