internal override ReaderBase Read() { Match match = AttrSelectorReader.Pattern.Match(this.Param, this.Position); if (match.Success) { this.Ascend(match); bool next = !this.PreSpace; string name = match.GetValue("name"); string value = null; Group group = match.Groups["value"]; if (group.Success) { value = group.Value; } this.AddFilter(new FilterByAttr(name, value), next); return(this.Pass <SelectorReader>()); } throw new SelectorParamException(this.Position, this.Param[this.Position].ToString()); }
public void MatchExtensions(HttpListenerContext ctx, Match match) { // Expect two query parameters, "string=query_string" and "int=200" try { string strVal = match.GetValue("string"); Assert.AreEqual("MyString", strVal); int intVal = match.GetValue <int>("int"); Assert.AreEqual(100, intVal); SendTextResponse(ctx, "success"); } catch (Exception ex) { SendTextResponse(ctx, "fail: " + ex.ToString()); } }
private static void SetFieldsFromMatch(Match match, ref CanonicalName result, bool isCanonical) { result.IsCanonical = isCanonical; var version1 = match.GetValue("v1", "0"); var version2 = match.GetValue("v2", ".0"); var version3 = match.GetValue("v3", ".0"); var version4 = match.GetValue("v4", ".0"); result.Name = match.GetValue("name").IfNullOrEmpty("*"); result.MatchVersionOrGreater = !(match.Groups["v1"].Success && match.Groups["v2"].Success && match.Groups["v3"].Success && match.Groups["v4"].Success) || match.Groups["plus"].Success; result.Version = version1 + version2 + version3 + version4; // no version is always a wildcard match. if (result.Version == 0) { result.MatchVersionOrGreater = true; } // if we are a wildcard match (however it happened), we're not canonical if (result.MatchVersionOrGreater) { // this isn't canonical. result.IsCanonical = false; } result.Architecture = match.GetValue("arch").IfNullOrEmpty("*"); if (result.Architecture == Architecture.Unknown || result.Architecture == Architecture.Auto) { // if the architecture is unknown/auto, we're not canonical result.Architecture = Architecture.Auto; isCanonical = false; } // an empty flavor is a valid value. if we're not going to be a canonical name anyway, then go for wide open. result.Flavor = isCanonical ? match.GetValue("flavor") : match.GetValue("flavor").IfNullOrEmpty("*"); result.PublicKeyToken = match.GetValue("pkt").IfNullOrEmpty("*"); }
protected override IEnumerable <Element> EvalThis(Document document, IEnumerable <Element> source) { if (this.Condition.CompareIgnoreCase("first")) { return(source.Take(1)); } else if (this.Condition.CompareIgnoreCase("last")) { Element last = source.LastOrDefault(); if (last.IsNull()) { return(new Element[0]); } else { return(last.ConstructArray()); } } else if (this.Condition.CompareIgnoreCase("checkbox")) { return(source.SelectMany(i => i.EnumerateAllElements().Where( j => j.Name.CompareIgnoreCase("input") && j.getAttribute("type").CompareIgnoreCase("checkbox")))); } else { Match eq = FilterByOther.EqPattern.Match(this.Condition); if (eq.Success) { int?index = eq.GetValue("index").ToInt(); if (index.IsNotNull()) { return(source.SelectMany(i => i.EnumerateAllElements()).Skip(index.Value).Take(1)); } else { throw new SelectorParamException(this.Index, this.Condition); } } else { Match gt = FilterByOther.GtPattern.Match(this.Condition); if (gt.Success) { int?index = gt.GetValue("index").ToInt(); if (index.IsNotNull()) { return(source.SelectMany(i => i.EnumerateAllElements()).Skip(index.Value + 1)); } else { throw new SelectorParamException(this.Index, this.Condition); } } else { Match lt = FilterByOther.LtPattern.Match(this.Condition); if (lt.Success) { int?index = lt.GetValue("index").ToInt(); if (index.IsNotNull()) { return(source.SelectMany(i => i.EnumerateAllElements()).Take(index.Value)); } else { throw new SelectorParamException(this.Index, this.Condition); } } else { throw new SelectorParamException(this.Index, this.Condition); } } } } }
public void MatchExtensions( HttpListenerContext ctx, Match match ) { // Expect two query parameters, "string=query_string" and "int=200" try { string strVal = match.GetValue("string"); Assert.AreEqual("MyString", strVal); int intVal = match.GetValue<int>("int"); Assert.AreEqual(100, intVal); SendTextResponse( ctx, "success" ); } catch (Exception ex) { SendTextResponse( ctx, "fail: " + ex.ToString() ); } }
private static bool GetShow(Match match) => Types[match.GetValue("show").ToLower()];
private static OrderByDirection GetDirection(Match match) => Types[match.GetValue("direction").ToLower()];