Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Xml / System / Xml / XPath / Internal / FunctionQuery.cs / 1305376 / FunctionQuery.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace MS.Internal.Xml.XPath { using System; using System.Xml; using System.Xml.Xsl; using System.Xml.XPath; using System.Diagnostics; using System.Globalization; using System.Collections.Generic; internal sealed class FunctionQuery : ExtensionQuery { private IListargs; private IXsltContextFunction function; public FunctionQuery(string prefix, string name, List args) : base(prefix, name) { this.args = args; } private FunctionQuery(FunctionQuery other) : base(other) { this.function = other.function; Query[] tmp = new Query[other.args.Count]; { for (int i = 0; i < tmp.Length; i ++) { tmp[i] = Clone(other.args[i]); } args = tmp; } this.args = tmp; } public override void SetXsltContext(XsltContext context) { if (context == null) { throw XPathException.Create(Res.Xp_NoContext); } if (this.xsltContext != context) { xsltContext = context; foreach (Query argument in args) { argument.SetXsltContext(context); } XPathResultType[] argTypes = new XPathResultType[args.Count]; for(int i = 0; i < args.Count; i ++) { argTypes[i] = args[i].StaticType; } function = xsltContext.ResolveFunction(prefix, name, argTypes); // KB article allows to return null, see http://support.microsoft.com/?kbid=324462#6 if (function == null) { throw XPathException.Create(Res.Xp_UndefFunc, QName); } } } public override object Evaluate(XPathNodeIterator nodeIterator) { if (xsltContext == null) { throw XPathException.Create(Res.Xp_NoContext); } // calculate arguments: object[] argVals = new object[args.Count]; for (int i = 0; i < args.Count; i ++) { argVals[i] = args[i].Evaluate(nodeIterator); if (argVals[i] is XPathNodeIterator) {// ForBack Compat. To protect our queries from users. bug#372077 & 20006123 argVals[i] = new XPathSelectionIterator(nodeIterator.Current, args[i]); } } try { return ProcessResult(function.Invoke(xsltContext, argVals, nodeIterator.Current)); } catch(Exception ex) { throw XPathException.Create(Res.Xp_FunctionFailed, QName, ex); } } public override XPathNavigator MatchNode(XPathNavigator navigator) { if (name != "key" && prefix.Length != 0) { throw XPathException.Create(Res.Xp_InvalidPattern); } this.Evaluate(new XPathSingletonIterator(navigator, /*moved:*/true)); XPathNavigator nav = null; while ((nav = this.Advance()) != null) { if (nav.IsSamePosition(navigator)) { return nav; } } return nav; } public override XPathResultType StaticType { get { XPathResultType result = function != null ? function.ReturnType : XPathResultType.Any; if (result == XPathResultType.Error) { // In v.1 we confused Error & Any so now for backward compatibility we should allow users to return any of them. result = XPathResultType.Any; } return result; } } public override XPathNodeIterator Clone() { return new FunctionQuery(this); } public override void PrintQuery(XmlWriter w) { w.WriteStartElement(this.GetType().Name); w.WriteAttributeString("name", prefix.Length != 0 ? prefix + ':' + name : name); foreach(Query arg in this.args) { arg.PrintQuery(w); } w.WriteEndElement(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EntityCommandDefinition.cs
- BrowserTree.cs
- SqlDataSourceParameterParser.cs
- XmlEncoding.cs
- ipaddressinformationcollection.cs
- BamlReader.cs
- DataRecordInternal.cs
- ClaimTypeElementCollection.cs
- ReachPageContentCollectionSerializerAsync.cs
- EncodingTable.cs
- ObjectViewListener.cs
- LinearKeyFrames.cs
- Guid.cs
- SqlDataReader.cs
- SmtpMail.cs
- TextBoxLine.cs
- EventLogStatus.cs
- StringAttributeCollection.cs
- Literal.cs
- CodeIndexerExpression.cs
- DataList.cs
- RelativeSource.cs
- TreeIterator.cs
- XmlNavigatorStack.cs
- PropertyEmitterBase.cs
- MultiView.cs
- HtmlString.cs
- CheckBoxFlatAdapter.cs
- FieldAccessException.cs
- SqlConnectionPoolProviderInfo.cs
- AutomationAttributeInfo.cs
- ToolStripScrollButton.cs
- DataBindEngine.cs
- Site.cs
- TextBlock.cs
- Color.cs
- LassoHelper.cs
- BamlBinaryWriter.cs
- wgx_commands.cs
- Padding.cs
- MostlySingletonList.cs
- ClientUtils.cs
- SqlNamer.cs
- TypedElement.cs
- RawStylusInputCustomDataList.cs
- GridViewItemAutomationPeer.cs
- RelatedImageListAttribute.cs
- CommandHelper.cs
- DataGridViewRowErrorTextNeededEventArgs.cs
- BaseInfoTable.cs
- ListComponentEditorPage.cs
- ByteAnimationUsingKeyFrames.cs
- IdnMapping.cs
- HitTestParameters.cs
- DetailsViewUpdatedEventArgs.cs
- ApplicationException.cs
- Propagator.Evaluator.cs
- mongolianshape.cs
- UnsafeNativeMethods.cs
- ProxyWebPartConnectionCollection.cs
- DataGridAddNewRow.cs
- DataGridAutoFormat.cs
- CharStorage.cs
- AssemblyAssociatedContentFileAttribute.cs
- ListManagerBindingsCollection.cs
- arclist.cs
- RepeatButton.cs
- PreservationFileWriter.cs
- XamlBuildTaskServices.cs
- ListDictionaryInternal.cs
- EntityReference.cs
- DataDocumentXPathNavigator.cs
- EntitySetBaseCollection.cs
- WmlLabelAdapter.cs
- VectorCollectionConverter.cs
- OdbcParameter.cs
- IdentityHolder.cs
- DataRecordObjectView.cs
- MapPathBasedVirtualPathProvider.cs
- Reference.cs
- MimePart.cs
- PagedDataSource.cs
- ResourceExpressionBuilder.cs
- UInt64.cs
- PixelFormats.cs
- EncryptedType.cs
- DesignerCategoryAttribute.cs
- CellRelation.cs
- SystemIcmpV4Statistics.cs
- WeakHashtable.cs
- Canvas.cs
- ComPlusInstanceProvider.cs
- OutOfMemoryException.cs
- RolePrincipal.cs
- As.cs
- ReferenceConverter.cs
- TimeSpanValidator.cs
- XsdCachingReader.cs
- DoubleLinkList.cs
- SqlDataSourceConnectionPanel.cs