protected void ParseParameter() { XPathNavigator nav = this.Navigator; string nameValue = nav.GetAttribute("name", ""); if (this.Parameters.Contains(nameValue)) { return; } PageParameterInfo paramInfo = null; if (nav.MoveToAttribute("bind", WebModule.Namespace)) { var exprBuilderContext = new BindingExpressionContext(this, nav.Clone()); BindingExpressionInfo exprInfo = null; try { exprInfo = BindingExpressionBuilder.ParseExpr(nav.Value, exprBuilderContext); } catch (Exception ex) { throw CreateParseException(ex.Message); } if (exprInfo != null) { exprInfo.LineNumber = ((IXmlLineInfo)nav).LineNumber; } nav.MoveToParent(); IDictionary<string, string> namespacesInScope = nav.GetNamespacesInScope(XmlNamespaceScope.All); bool hasDefaultValue = !String.IsNullOrEmpty(nav.GetAttribute("select", "")); string asValue = nav.GetAttribute("as", ""); bool required = nav.GetAttribute("required", "") == "yes"; paramInfo = PageParameterInfo.FromSequenceType(nameValue, asValue, namespacesInScope); if (hasDefaultValue) { if (paramInfo.MinLength > 0) { paramInfo.MinLength = 0; } } else if (required) { if (paramInfo.MinLength == 0) { paramInfo.MinLength = 1; } } paramInfo.Binding = exprInfo; } if (paramInfo != null) { this.Parameters.Add(paramInfo); } }
public static PageParameterInfo FromSequenceType(string name, string sequenceType, IDictionary <string, string> namespacesInScope) { var param = new PageParameterInfo(name); if (!String.IsNullOrEmpty(sequenceType)) { if (sequenceType.Length < 3) { throw new ArgumentException("Unrecognized SequenceType.", "sequenceType"); } string occurrenceIndicator = OcurrenceIndicatorRegex.Match(sequenceType).Value; string itemType = String.IsNullOrEmpty(occurrenceIndicator) ? sequenceType : sequenceType.Substring(0, sequenceType.Length - 1); // ensure non ParenthesizedItemType if (itemType[0] == '(') { itemType = itemType.Substring(1, itemType.Length - 1); } switch (occurrenceIndicator) { default: param.MinLength = 1; param.MaxLength = 1; break; case "?": param.MinLength = 0; param.MaxLength = 1; break; case "*": param.MinLength = 0; param.MaxLength = -1; break; case "+": param.MinLength = 1; param.MaxLength = -1; break; } if (itemType.Contains("(")) { // not AtomicType if (itemType == "empty-sequence()") { param.MinLength = param.MaxLength = 0; } } else if (itemType.Contains(":")) { string[] parts = itemType.Split(':'); string atomicTypePrefix = parts[0]; string atomicTypeLocal = parts[1]; if (namespacesInScope == null) { throw new ArgumentNullException("namespacesInScope", "namespacesInScope is needed to resolve the ItemType."); } if (!namespacesInScope.ContainsKey(atomicTypePrefix)) { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "namespacesInScope does not contain a mapping for prefix '{0}'.", atomicTypePrefix), "namespacesInScope"); } string atomicTypeNamespace = namespacesInScope[atomicTypePrefix]; param.AtomicTypeName = new XmlQualifiedName(atomicTypeLocal, atomicTypeNamespace); } else { throw new ArgumentException("Unrecognized ItemType.", "sequenceType"); } } return(param); }