public XPathMutableCursor(IXmlNode parent, CompiledXPath path, IXmlIncludedTypeMap knownTypes, IXmlNamespaceSource namespaces, CursorFlags flags) : base(path, namespaces, parent) { if (null == parent) { throw Error.ArgumentNull("parent"); } if (null == path) { throw Error.ArgumentNull("path"); } if (null == knownTypes) { throw Error.ArgumentNull("knownTypes"); } if (!path.IsCreatable) { throw Error.XPathNotCreatable(path); } this.step = path.FirstStep; this.knownTypes = knownTypes; this.flags = flags; var source = parent.RequireRealizable <XPathNavigator>(); if (source.IsReal) { iterator = new XPathBufferedNodeIterator( source.Value.Select(path.FirstStep.Path)); } }
public XPathReadOnlyCursor( IXmlNode parent, CompiledXPath path, IXmlIncludedTypeMap includedTypes, IXmlNamespaceSource namespaces, CursorFlags flags ) : base(path, namespaces, parent) { if (parent == null) { throw Error.ArgumentNull(nameof(parent)); } if (path == null) { throw Error.ArgumentNull(nameof(path)); } if (includedTypes == null) { throw Error.ArgumentNull(nameof(includedTypes)); } this.includedTypes = includedTypes; this.flags = flags; Reset(); }
private static bool ParseStep(Tokenizer source, CompiledXPath path, ref CompiledXPathStep step) { var previous = step; var start = source.Index; if (!ParseNodeCore(source, StepFactory, ref step)) { return(false); } if (step != previous) { var text = source.GetConsumedText(start); step.Path = XPathExpression.Compile(text); if (previous == null) { path.FirstStep = step; } else { LinkNodes(previous, step); } path.Depth++; } return(true); }
public XPathAttribute(string path) { if (path == null) throw Error.ArgumentNull("path"); this.getPath = XPathCompiler.Compile(path); this.setPath = this.getPath; }
internal static Exception XPathNotCreatable(CompiledXPath path) { var message = string.Format( "The path '{0}' is not a creatable XPath expression.", path.Path.Expression); return(new XPathException(message)); }
public IXmlCursor Select( CompiledXPath path, IXmlIncludedTypeMap knownTypes, IXmlNamespaceSource namespaces, CursorFlags flags ) { return(node.Select(path, knownTypes, namespaces, flags)); }
public XPathAttribute(string get, string set) { if (get == null) throw Error.ArgumentNull("get"); if (set == null) throw Error.ArgumentNull("set"); this.getPath = XPathCompiler.Compile(get); this.setPath = XPathCompiler.Compile(set); }
public XPathAttribute(string path) { if (path == null) { throw Error.ArgumentNull("path"); } this.getPath = XPathCompiler.Compile(path); this.setPath = this.getPath; }
public IXmlCursor Select( CompiledXPath path, IXmlIncludedTypeMap includedTypes, IXmlNamespaceSource namespaces, CursorFlags flags ) { return(flags.SupportsMutation() ? (IXmlCursor) new XPathMutableCursor(this, path, includedTypes, namespaces, flags) : (IXmlCursor) new XPathReadOnlyCursor(this, path, includedTypes, namespaces, flags)); }
public XPathAttribute(string get, string set) { if (get == null) { throw Error.ArgumentNull("get"); } if (set == null) { throw Error.ArgumentNull("set"); } this.getPath = XPathCompiler.Compile(get); this.setPath = XPathCompiler.Compile(set); }
public XPathReadOnlyCursor(IXmlNode parent, CompiledXPath path, IXmlIncludedTypeMap includedTypes, IXmlNamespaceSource namespaces, CursorFlags flags) : base(path, namespaces, parent) { if (parent == null) throw Error.ArgumentNull("parent"); if (path == null) throw Error.ArgumentNull("path"); if (includedTypes == null) throw Error.ArgumentNull("includedTypes"); this.includedTypes = includedTypes; this.flags = flags; Reset(); }
public void Configure(XPathAttribute attribute) { if (path != null) { throw Error.AttributeConflict(path.Path.Expression); } path = attribute.SetPath; if (path == attribute.GetPath) { return; } else if (Serializer.CanGetStub) { throw Error.SeparateGetterSetterOnComplexType(path.Path.Expression); } defaultAccessor = new DefaultAccessor(this, attribute.GetPath); }
public XPathMutableCursor(IXmlNode parent, CompiledXPath path, IXmlIncludedTypeMap knownTypes, IXmlNamespaceSource namespaces, CursorFlags flags) : base(path, namespaces, parent) { if (null == parent) throw Error.ArgumentNull("parent"); if (null == path) throw Error.ArgumentNull("path"); if (null == knownTypes) throw Error.ArgumentNull("knownTypes"); if (!path.IsCreatable) throw Error.XPathNotCreatable(path); this.step = path.FirstStep; this.knownTypes = knownTypes; this.flags = flags; var source = parent.RequireRealizable<XPathNavigator>(); if (source.IsReal) iterator = new XPathBufferedNodeIterator( source.Value.Select(path.FirstStep.Path)); }
private static bool ParsePath(Tokenizer source, CompiledXPath path) { for (CompiledXPathStep step = null;;) { if (!ParseStep(source, path, ref step)) { return(false); } if (source.Token == Token.EndOfInput) { return(true); } if (!Consume(source, Token.StepSeparator)) { return(false); } if (step.IsAttribute) { return(false); } } }
public static CompiledXPath Compile(string path) { if (null == path) { throw Error.ArgumentNull("path"); } // Compile whole path to catch errors var result = new CompiledXPath(); result.Path = XPathExpression.Compile(path); // Try to split into individual path steps var tokenizer = new Tokenizer(path); if (!ParsePath(tokenizer, result)) { result.MakeNotCreatable(); } // Finish compilation result.Prepare(); return(result); }
public void Enlist(CompiledXPath path) { throw Error.NotSupported(); }
protected XPathNode(CompiledXPath path, IXmlNamespaceSource namespaces, IXmlNode parent) : base(namespaces, parent) { this.xpath = path; }
public virtual object Evaluate(CompiledXPath path) { return(node.Evaluate(path.Path)); }
public void Enlist(CompiledXPath path) { path.SetContext(XPathContext); }
protected abstract IXmlCursor Cursor(IXmlNode parent, CompiledXPath path, IXmlIncludedTypeMap includedTypes, CursorFlags flags);
public override object Evaluate(CompiledXPath path) { return(HasCurrent ? base.Evaluate(path) : null); }
public object Evaluate(CompiledXPath path) { return(node.Evaluate(path)); }
public virtual object Evaluate(CompiledXPath path) { return(node.CreateNavigator().Evaluate(path.Path)); }
public override object Evaluate(CompiledXPath path) { return HasCurrent ? base.Evaluate(path) : null; }
public DefaultAccessor(XPathBehaviorAccessor parent, CompiledXPath path) : base(parent.ClrType, parent.Context) { this.parent = parent; this.path = path; }
public XmlMetadata(DictionaryAdapterMeta meta, IEnumerable <string> reservedNamespaceUris) { if (meta == null) { throw Error.ArgumentNull("meta"); } if (reservedNamespaceUris == null) { throw Error.ArgumentNull("reservedNamespaceUris"); } source = meta; clrType = meta.Type; context = new XmlContext(this); includedTypes = new XmlIncludedTypeSet(); this.reservedNamespaceUris = reservedNamespaceUris as HashSet <string> ?? new HashSet <string>(reservedNamespaceUris); var xmlRoot = null as XmlRootAttribute; var xmlType = null as XmlTypeAttribute; var xmlDefaults = null as XmlDefaultsAttribute; var xmlInclude = null as XmlIncludeAttribute; var xmlNamespace = null as XmlNamespaceAttribute; var reference = null as ReferenceAttribute; var xPath = null as XPathAttribute; var xPathVariable = null as XPathVariableAttribute; var xPathFunction = null as XPathFunctionAttribute; foreach (var behavior in meta.Behaviors) { if (TryCast(behavior, ref xmlRoot)) { } else if (TryCast(behavior, ref xmlType)) { } else if (TryCast(behavior, ref xmlDefaults)) { } else if (TryCast(behavior, ref xmlInclude)) { AddPendingInclude(xmlInclude); } else if (TryCast(behavior, ref xmlNamespace)) { context.AddNamespace(xmlNamespace); } else if (TryCast(behavior, ref reference)) { } else if (TryCast(behavior, ref xPath)) { } else if (TryCast(behavior, ref xPathVariable)) { context.AddVariable(xPathVariable); } else if (TryCast(behavior, ref xPathFunction)) { context.AddFunction(xPathFunction); } } if (xmlDefaults != null) { qualified = xmlDefaults.Qualified; isNullable = xmlDefaults.IsNullable; } if (reference != null) { isReference = true; } typeLocalName = XmlConvert.EncodeLocalName ( (!meta.HasXmlType() ? null : meta.GetXmlType().NonEmpty()) ?? (xmlType == null ? null : xmlType.TypeName.NonEmpty()) ?? GetDefaultTypeLocalName(clrType) ); rootLocalName = XmlConvert.EncodeLocalName ( (xmlRoot == null ? null : xmlRoot.ElementName.NonEmpty()) ?? typeLocalName ); typeNamespaceUri = ( (xmlType == null ? null : xmlType.Namespace) ); rootNamespaceUri = ( (xmlRoot == null ? null : xmlRoot.Namespace) ); childNamespaceUri = ( typeNamespaceUri ?? rootNamespaceUri ); if (xPath != null) { path = xPath.GetPath; path.SetContext(context); } }
protected override IXmlCursor Cursor(IXmlNode parent, CompiledXPath path, IXmlIncludedTypeMap includedTypes, CursorFlags flags) { return new XPathMutableCursor(parent, path, includedTypes, NamespaceSource.Instance, flags); }