Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Xml / System / Xml / XPath / Internal / NumericExpr.cs / 1 / NumericExpr.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace MS.Internal.Xml.XPath { using System; using System.Xml; using System.Xml.XPath; using System.Diagnostics; using System.Globalization; using System.Xml.Xsl; internal sealed class NumericExpr : ValueQuery { private Operator.Op op; private Query opnd1; private Query opnd2; public NumericExpr(Operator.Op op, Query opnd1, Query opnd2) { Debug.Assert( op == Operator.Op.PLUS || op == Operator.Op.MINUS || op == Operator.Op.MUL || op == Operator.Op.DIV || op == Operator.Op.MOD ); Debug.Assert(opnd1 != null && opnd2 != null); if (opnd1.StaticType != XPathResultType.Number) { opnd1 = new NumberFunctions(Function.FunctionType.FuncNumber, opnd1); } if (opnd2.StaticType != XPathResultType.Number) { opnd2 = new NumberFunctions(Function.FunctionType.FuncNumber, opnd2); } this.op = op; this.opnd1 = opnd1; this.opnd2 = opnd2; } private NumericExpr(NumericExpr other) : base(other) { this.op = other.op; this.opnd1 = Clone(other.opnd1); this.opnd2 = Clone(other.opnd2); } public override void SetXsltContext(XsltContext context){ opnd1.SetXsltContext(context); opnd2.SetXsltContext(context); } public override object Evaluate(XPathNodeIterator nodeIterator) { return GetValue(this.op, XmlConvert.ToXPathDouble(opnd1.Evaluate(nodeIterator)), XmlConvert.ToXPathDouble(opnd2.Evaluate(nodeIterator)) ); } private static double GetValue(Operator.Op op, double n1, double n2) { Debug.Assert(op == Operator.Op.PLUS || op == Operator.Op.MINUS || op == Operator.Op.MOD || op == Operator.Op.DIV || op == Operator.Op.MUL); switch (op) { case Operator.Op.PLUS : return n1 + n2; case Operator.Op.MINUS : return n1 - n2; case Operator.Op.MOD : return n1 % n2; case Operator.Op.DIV : return n1 / n2; case Operator.Op.MUL : return n1 * n2; } return 0; } public override XPathResultType StaticType { get { return XPathResultType.Number; } } public override XPathNodeIterator Clone() { return new NumericExpr(this); } public override void PrintQuery(XmlWriter w) { w.WriteStartElement(this.GetType().Name); w.WriteAttributeString("op", op.ToString()); opnd1.PrintQuery(w); opnd2.PrintQuery(w); w.WriteEndElement(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace MS.Internal.Xml.XPath { using System; using System.Xml; using System.Xml.XPath; using System.Diagnostics; using System.Globalization; using System.Xml.Xsl; internal sealed class NumericExpr : ValueQuery { private Operator.Op op; private Query opnd1; private Query opnd2; public NumericExpr(Operator.Op op, Query opnd1, Query opnd2) { Debug.Assert( op == Operator.Op.PLUS || op == Operator.Op.MINUS || op == Operator.Op.MUL || op == Operator.Op.DIV || op == Operator.Op.MOD ); Debug.Assert(opnd1 != null && opnd2 != null); if (opnd1.StaticType != XPathResultType.Number) { opnd1 = new NumberFunctions(Function.FunctionType.FuncNumber, opnd1); } if (opnd2.StaticType != XPathResultType.Number) { opnd2 = new NumberFunctions(Function.FunctionType.FuncNumber, opnd2); } this.op = op; this.opnd1 = opnd1; this.opnd2 = opnd2; } private NumericExpr(NumericExpr other) : base(other) { this.op = other.op; this.opnd1 = Clone(other.opnd1); this.opnd2 = Clone(other.opnd2); } public override void SetXsltContext(XsltContext context){ opnd1.SetXsltContext(context); opnd2.SetXsltContext(context); } public override object Evaluate(XPathNodeIterator nodeIterator) { return GetValue(this.op, XmlConvert.ToXPathDouble(opnd1.Evaluate(nodeIterator)), XmlConvert.ToXPathDouble(opnd2.Evaluate(nodeIterator)) ); } private static double GetValue(Operator.Op op, double n1, double n2) { Debug.Assert(op == Operator.Op.PLUS || op == Operator.Op.MINUS || op == Operator.Op.MOD || op == Operator.Op.DIV || op == Operator.Op.MUL); switch (op) { case Operator.Op.PLUS : return n1 + n2; case Operator.Op.MINUS : return n1 - n2; case Operator.Op.MOD : return n1 % n2; case Operator.Op.DIV : return n1 / n2; case Operator.Op.MUL : return n1 * n2; } return 0; } public override XPathResultType StaticType { get { return XPathResultType.Number; } } public override XPathNodeIterator Clone() { return new NumericExpr(this); } public override void PrintQuery(XmlWriter w) { w.WriteStartElement(this.GetType().Name); w.WriteAttributeString("op", op.ToString()); opnd1.PrintQuery(w); opnd2.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
- xamlnodes.cs
- OleDbRowUpdatedEvent.cs
- KeyValuePairs.cs
- DataTableReaderListener.cs
- EncodingConverter.cs
- StandardCommands.cs
- ObjectDataSourceSelectingEventArgs.cs
- CfgSemanticTag.cs
- ConnectionPoolManager.cs
- SemanticBasicElement.cs
- TextReader.cs
- WindowsFormsSectionHandler.cs
- WorkflowPersistenceService.cs
- StorageEntityTypeMapping.cs
- BoundsDrawingContextWalker.cs
- safex509handles.cs
- FixedDocumentSequencePaginator.cs
- ToolStripContainer.cs
- XmlAttributeOverrides.cs
- CustomAssemblyResolver.cs
- WebServiceHost.cs
- IconHelper.cs
- DiscoveryClientChannelBase.cs
- BinaryConverter.cs
- GroupItemAutomationPeer.cs
- ApplyImportsAction.cs
- RenderingEventArgs.cs
- Exceptions.cs
- DbTransaction.cs
- EntityAdapter.cs
- FocusWithinProperty.cs
- FromRequest.cs
- BooleanToVisibilityConverter.cs
- DesignerCatalogPartChrome.cs
- datacache.cs
- ListViewItemCollectionEditor.cs
- AnnotationHighlightLayer.cs
- StrongNameHelpers.cs
- TableRowGroup.cs
- WorkflowStateRollbackService.cs
- ListViewInsertionMark.cs
- baseshape.cs
- _AutoWebProxyScriptHelper.cs
- LineBreak.cs
- RichTextBox.cs
- Encoder.cs
- QueryIntervalOp.cs
- AsyncStreamReader.cs
- GroupDescription.cs
- OutputScope.cs
- UIHelper.cs
- Schema.cs
- SmtpReplyReader.cs
- ZoneLinkButton.cs
- ObjectAnimationUsingKeyFrames.cs
- StartUpEventArgs.cs
- ScrollBar.cs
- ProxyAttribute.cs
- Context.cs
- PropertyOrder.cs
- DataGridTableCollection.cs
- CodeRegionDirective.cs
- ExecutionContext.cs
- NavigationWindowAutomationPeer.cs
- DispatcherExceptionEventArgs.cs
- ExpiredSecurityTokenException.cs
- DataGridViewCellStyleChangedEventArgs.cs
- DataTableNewRowEvent.cs
- AuthenticationException.cs
- IsolatedStorageSecurityState.cs
- MimeTypePropertyAttribute.cs
- ClientSideQueueItem.cs
- SqlVersion.cs
- BamlRecords.cs
- BitmapPalettes.cs
- HitTestWithGeometryDrawingContextWalker.cs
- VSWCFServiceContractGenerator.cs
- List.cs
- EventLogPermission.cs
- SoapClientProtocol.cs
- RegionIterator.cs
- ClientSideQueueItem.cs
- DiagnosticsConfiguration.cs
- RequestCacheValidator.cs
- InstanceLockQueryResult.cs
- BindingContext.cs
- TemplatePartAttribute.cs
- CanonicalFontFamilyReference.cs
- XmlSchemaExternal.cs
- Int32EqualityComparer.cs
- PropertyInfo.cs
- SatelliteContractVersionAttribute.cs
- AuthenticationSection.cs
- WebPartZone.cs
- Msec.cs
- NegationPusher.cs
- IIS7UserPrincipal.cs
- TypeSystemHelpers.cs
- MessagePartProtectionMode.cs
- SafeEventLogWriteHandle.cs