private void Operate( SelectorParam param, Action <Element, Node[]> nodesAction, Action <Element, string> stringAction, Action <Element, Query> queryAction) { if (param.IsNotNull()) { IEnumerable <Element> elements = this.Select(); if (param.NodesValue.IsNotNull()) { foreach (Element i in elements) { nodesAction(i, param.NodesValue); } } else if (param.StringValue.IsNotNull()) { foreach (Element i in elements) { stringAction(i, param.StringValue); } } else { foreach (Element i in elements) { queryAction(i, param.QueryValue); } } } }
private Selector(Document document, SelectorParam selectorParam) { this.Document = document; this.Param = selectorParam; this.ExtFilterList = new List <Func <IEnumerable <Element>, IEnumerable <Element> > >(); }
/// <summary> /// 设置元素的 innerHTML /// </summary> /// <param name="param"></param> /// <returns></returns> /// <exception cref="SelectorParamException">选择器参数错误</exception> public Query html(SelectorParam param) { this.Operate(param, (element, nodes) => { element.childNodes = nodes; }, (element, html) => { element.innerHTML = html; }, (element, query) => { IEnumerable <Element> elements = query.Select(); element.childNodes = elements.ToArray(); }); return(this); }