Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / ndp / fx / src / Xml / System / Xml / XPath / Internal / FunctionQuery.cs / 3 / 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. 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. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TransformPatternIdentifiers.cs
- DataTableNameHandler.cs
- TreeIterator.cs
- MenuItem.cs
- NativeMethods.cs
- StorageEntityTypeMapping.cs
- SuppressMergeCheckAttribute.cs
- BackgroundWorker.cs
- OutOfProcStateClientManager.cs
- NamespaceDecl.cs
- SqlCommandSet.cs
- COM2ExtendedUITypeEditor.cs
- RectValueSerializer.cs
- TimelineCollection.cs
- WebPartEditorApplyVerb.cs
- CompareValidator.cs
- WindowsUpDown.cs
- ContentElement.cs
- LinkUtilities.cs
- PlaceHolder.cs
- SrgsText.cs
- TemplateColumn.cs
- DocumentPageViewAutomationPeer.cs
- MatrixKeyFrameCollection.cs
- CompositeActivityDesigner.cs
- ProxyFragment.cs
- Crc32Helper.cs
- RuntimeConfigurationRecord.cs
- ConvertersCollection.cs
- HGlobalSafeHandle.cs
- ServiceReference.cs
- ListCommandEventArgs.cs
- ContextMenuStrip.cs
- SpecialNameAttribute.cs
- Pipe.cs
- NativeMethods.cs
- DataGridRow.cs
- AppSettingsSection.cs
- _AutoWebProxyScriptWrapper.cs
- ToolStripContentPanel.cs
- WebPartDescriptionCollection.cs
- UidManager.cs
- CallTemplateAction.cs
- TimeSpanOrInfiniteConverter.cs
- VideoDrawing.cs
- HybridDictionary.cs
- Timer.cs
- PageCatalogPart.cs
- SiteMapDataSource.cs
- XslCompiledTransform.cs
- UdpSocket.cs
- RepeaterItemEventArgs.cs
- TreeNodeStyle.cs
- UnwrappedTypesXmlSerializerManager.cs
- TemplatePagerField.cs
- ConfigurationStrings.cs
- CommandEventArgs.cs
- InvalidComObjectException.cs
- _BufferOffsetSize.cs
- TabletCollection.cs
- ExpressionBinding.cs
- ClientSideProviderDescription.cs
- GridViewPageEventArgs.cs
- ColorPalette.cs
- ListBindingConverter.cs
- BitmapSizeOptions.cs
- Vector3D.cs
- CompositeFontFamily.cs
- PersistenceContextEnlistment.cs
- TCPClient.cs
- TogglePattern.cs
- XmlILModule.cs
- Dictionary.cs
- MobileComponentEditorPage.cs
- ConnectionProviderAttribute.cs
- BindValidator.cs
- GridLengthConverter.cs
- HeaderUtility.cs
- Enum.cs
- StylusPoint.cs
- RegexCaptureCollection.cs
- propertytag.cs
- DefaultMemberAttribute.cs
- SignedXml.cs
- SelectionProcessor.cs
- TickBar.cs
- BaseConfigurationRecord.cs
- Util.cs
- TextFormatterContext.cs
- Selector.cs
- StreamGeometry.cs
- CodeTypeConstructor.cs
- MaterialGroup.cs
- transactioncontext.cs
- OrderedDictionaryStateHelper.cs
- XmlNamespaceDeclarationsAttribute.cs
- KeyboardEventArgs.cs
- CompositeCollection.cs
- ReadOnlyHierarchicalDataSource.cs
- BuiltInPermissionSets.cs