private PropertyExtractor GetAttributeExtractCombo(Type type, PropertyInfo property) { PropertyExtractor propertyExtractor = null; var comboExtract = AttributeUtil.GetAttribute <ComboExtractAttribute>(property); if (comboExtract != null) { var extractBys = comboExtract.Value; var selectors = ExtractorUtils.GetSelectors(extractBys); ISelector selector = new AndSelector(selectors); switch (comboExtract.Op) { case Op.And: selector = new AndSelector(selectors); break; case Op.Or: selector = new OrSelector(selectors); break; } var source = comboExtract.Source == ExtractSource.RawHtml ? Source.RawHtml : Source.Html; propertyExtractor = new PropertyExtractor(property, selector, source, comboExtract.NotNull, comboExtract.IsMulti || typeof(List <object>).IsAssignableFrom(property.GetType())); } return(propertyExtractor); }
private PropertyExtractor GetAttributeExtractBy(Type type, PropertyInfo property) { PropertyExtractor propertyExtractor = null; var extractBy = AttributeUtil.GetAttribute <ExtractByAttribute>(property); if (extractBy != null) { var selector = ExtractorUtils.GetSelector(extractBy); var sourceTmp = extractBy.Source; if (extractBy.Type == ExtractType.JsonPath) { sourceTmp = ExtractSource.RawText; } Source source = Source.Html; switch (sourceTmp) { case ExtractSource.RawText: source = Source.RawText; break; case ExtractSource.RawHtml: source = Source.RawHtml; break; case ExtractSource.SelectedHtml: source = Source.Html; break; } propertyExtractor = new PropertyExtractor(property, selector, source, extractBy.NotNull, true); } return(propertyExtractor); }
private void SetProperty(object obj, PropertyExtractor propertyExtractor, object value) { if (value == null) { return; } if (propertyExtractor.SetterMethod != null) { propertyExtractor.SetterMethod.Invoke(obj, parameters: new object[] { value }); } propertyExtractor.Property.SetValue(obj, value); }
private PropertyExtractor GetAttributeExtractByUrl(Type type, PropertyInfo property) { PropertyExtractor propertyExtractor = null; var extractByUrlAttr = AttributeUtil.GetAttribute <ExtractByUrlAttribute>(property); if (extractByUrlAttr != null) { var regexPattern = extractByUrlAttr.Value; if (regexPattern.Trim().Equals("")) { regexPattern = ".*"; } propertyExtractor = new PropertyExtractor(property, new RegexSelector(regexPattern), Source.Url, extractByUrlAttr.NotNull, extractByUrlAttr.IsMulti || typeof(List <object>).IsAssignableFrom(property.GetType())); } return(propertyExtractor); }