Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Query / InternalTrees / Rule.cs / 1305376 / Rule.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; namespace System.Data.Query.InternalTrees { ////// A Rule - more specifically, a transformation rule - describes an action that is to /// be taken when a specific kind of subtree is found in the tree /// internal abstract class Rule { ////// The "callback" function for each rule. /// Every callback function must return true if the subtree has /// been modified (or a new subtree has been returned); and must return false /// otherwise. If the root of the subtree has not changed, but some internal details /// of the subtree have changed, it is the responsibility of the rule to update any /// local bookkeeping information. /// /// The rule processing context /// the subtree to operate on /// possibly transformed subtree ///transformation status - true, if there was some change; false otherwise internal delegate bool ProcessNodeDelegate(RuleProcessingContext context, Node subTree, out Node newSubTree); #region private state private ProcessNodeDelegate m_nodeDelegate; private OpType m_opType; #endregion #region Constructors ////// Basic constructor /// /// The OpType we're interested in processing /// The callback to invoke protected Rule(OpType opType, ProcessNodeDelegate nodeProcessDelegate) { Debug.Assert(nodeProcessDelegate != null, "null process delegate"); Debug.Assert(opType != OpType.NotValid, "bad OpType"); Debug.Assert(opType != OpType.Leaf, "bad OpType - Leaf"); m_opType = opType; m_nodeDelegate = nodeProcessDelegate; } #endregion #region protected methods #endregion #region public methods ////// Does the rule match the current node? /// /// the node in question ///true, if a match was found internal abstract bool Match(Node node); ////// We need to invoke the specified callback on the subtree in question - but only /// if the match succeeds /// /// Current rule processing context /// The node (subtree) to process /// the (possibly) modified subtree ///true, if the subtree was modified internal bool Apply(RuleProcessingContext ruleProcessingContext, Node node, out Node newNode) { // invoke the real callback return m_nodeDelegate(ruleProcessingContext, node, out newNode); } ////// The OpType we're interested in transforming /// internal OpType RuleOpType { get { return m_opType; } } #if DEBUG ////// The method name for the rule /// internal string MethodName { get { return m_nodeDelegate.Method.Name; } } #endif #endregion } ////// A SimpleRule is a rule that specifies a specific OpType to look for, and an /// appropriate action to take when such an Op is identified /// internal sealed class SimpleRule : Rule { #region private state #endregion #region constructors ////// Basic constructor. /// /// The OpType we're interested in /// The callback to invoke when we see such an Op internal SimpleRule(OpType opType, ProcessNodeDelegate processDelegate) : base(opType, processDelegate) { } #endregion #region overriden methods internal override bool Match(Node node) { return node.Op.OpType == this.RuleOpType; } #endregion } ////// A PatternMatchRule allows for a pattern to be specified to identify interesting /// subtrees, rather than just an OpType /// internal sealed class PatternMatchRule: Rule { #region private state private Node m_pattern; #endregion #region constructors ////// Basic constructor /// /// The pattern to look for /// The callback to invoke when such a pattern is identified internal PatternMatchRule(Node pattern, ProcessNodeDelegate processDelegate) : base(pattern.Op.OpType, processDelegate) { Debug.Assert(pattern != null, "null pattern"); Debug.Assert(pattern.Op != null, "null pattern Op"); m_pattern = pattern; } #endregion #region private methods private bool Match(Node pattern, Node original) { if (pattern.Op.OpType == OpType.Leaf) return true; if (pattern.Op.OpType != original.Op.OpType) return false; if (pattern.Children.Count != original.Children.Count) return false; for (int i = 0; i < pattern.Children.Count; i++) if (!Match(pattern.Children[i], original.Children[i])) return false; return true; } #endregion #region overridden methods internal override bool Match(Node node) { return Match(m_pattern, node); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; namespace System.Data.Query.InternalTrees { ////// A Rule - more specifically, a transformation rule - describes an action that is to /// be taken when a specific kind of subtree is found in the tree /// internal abstract class Rule { ////// The "callback" function for each rule. /// Every callback function must return true if the subtree has /// been modified (or a new subtree has been returned); and must return false /// otherwise. If the root of the subtree has not changed, but some internal details /// of the subtree have changed, it is the responsibility of the rule to update any /// local bookkeeping information. /// /// The rule processing context /// the subtree to operate on /// possibly transformed subtree ///transformation status - true, if there was some change; false otherwise internal delegate bool ProcessNodeDelegate(RuleProcessingContext context, Node subTree, out Node newSubTree); #region private state private ProcessNodeDelegate m_nodeDelegate; private OpType m_opType; #endregion #region Constructors ////// Basic constructor /// /// The OpType we're interested in processing /// The callback to invoke protected Rule(OpType opType, ProcessNodeDelegate nodeProcessDelegate) { Debug.Assert(nodeProcessDelegate != null, "null process delegate"); Debug.Assert(opType != OpType.NotValid, "bad OpType"); Debug.Assert(opType != OpType.Leaf, "bad OpType - Leaf"); m_opType = opType; m_nodeDelegate = nodeProcessDelegate; } #endregion #region protected methods #endregion #region public methods ////// Does the rule match the current node? /// /// the node in question ///true, if a match was found internal abstract bool Match(Node node); ////// We need to invoke the specified callback on the subtree in question - but only /// if the match succeeds /// /// Current rule processing context /// The node (subtree) to process /// the (possibly) modified subtree ///true, if the subtree was modified internal bool Apply(RuleProcessingContext ruleProcessingContext, Node node, out Node newNode) { // invoke the real callback return m_nodeDelegate(ruleProcessingContext, node, out newNode); } ////// The OpType we're interested in transforming /// internal OpType RuleOpType { get { return m_opType; } } #if DEBUG ////// The method name for the rule /// internal string MethodName { get { return m_nodeDelegate.Method.Name; } } #endif #endregion } ////// A SimpleRule is a rule that specifies a specific OpType to look for, and an /// appropriate action to take when such an Op is identified /// internal sealed class SimpleRule : Rule { #region private state #endregion #region constructors ////// Basic constructor. /// /// The OpType we're interested in /// The callback to invoke when we see such an Op internal SimpleRule(OpType opType, ProcessNodeDelegate processDelegate) : base(opType, processDelegate) { } #endregion #region overriden methods internal override bool Match(Node node) { return node.Op.OpType == this.RuleOpType; } #endregion } ////// A PatternMatchRule allows for a pattern to be specified to identify interesting /// subtrees, rather than just an OpType /// internal sealed class PatternMatchRule: Rule { #region private state private Node m_pattern; #endregion #region constructors ////// Basic constructor /// /// The pattern to look for /// The callback to invoke when such a pattern is identified internal PatternMatchRule(Node pattern, ProcessNodeDelegate processDelegate) : base(pattern.Op.OpType, processDelegate) { Debug.Assert(pattern != null, "null pattern"); Debug.Assert(pattern.Op != null, "null pattern Op"); m_pattern = pattern; } #endregion #region private methods private bool Match(Node pattern, Node original) { if (pattern.Op.OpType == OpType.Leaf) return true; if (pattern.Op.OpType != original.Op.OpType) return false; if (pattern.Children.Count != original.Children.Count) return false; for (int i = 0; i < pattern.Children.Count; i++) if (!Match(pattern.Children[i], original.Children[i])) return false; return true; } #endregion #region overridden methods internal override bool Match(Node node) { return Match(m_pattern, node); } #endregion } } // 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
- TabPanel.cs
- FileStream.cs
- DataBoundControl.cs
- Walker.cs
- TextMessageEncodingElement.cs
- DataTableCollection.cs
- ProbeDuplex11AsyncResult.cs
- FieldNameLookup.cs
- Translator.cs
- DigestComparer.cs
- FlowLayoutSettings.cs
- Privilege.cs
- InvalidPropValue.cs
- webeventbuffer.cs
- Page.cs
- MsmqProcessProtocolHandler.cs
- ScaleTransform3D.cs
- AppDomainEvidenceFactory.cs
- XmlQueryCardinality.cs
- ViewDesigner.cs
- FormsAuthenticationModule.cs
- DeviceContext.cs
- SchemaImporterExtensionsSection.cs
- ColumnMap.cs
- CompositeCollectionView.cs
- MimeTypePropertyAttribute.cs
- ToolStripContentPanelRenderEventArgs.cs
- TaiwanLunisolarCalendar.cs
- HwndSource.cs
- EasingFunctionBase.cs
- DataGridViewIntLinkedList.cs
- MimeFormatter.cs
- HyperLinkField.cs
- HtmlInputSubmit.cs
- HMACSHA1.cs
- DurationConverter.cs
- TdsParserSafeHandles.cs
- SwitchElementsCollection.cs
- AsyncPostBackTrigger.cs
- Lease.cs
- DiscoveryClient.cs
- XmlIlTypeHelper.cs
- AdCreatedEventArgs.cs
- SkipQueryOptionExpression.cs
- serverconfig.cs
- DeferredElementTreeState.cs
- ToolStripButton.cs
- TextHintingModeValidation.cs
- ParallelTimeline.cs
- ButtonBase.cs
- DomainUpDown.cs
- EntityViewGenerator.cs
- JournalEntry.cs
- ResourcePermissionBase.cs
- BindableTemplateBuilder.cs
- HttpDebugHandler.cs
- Win32NamedPipes.cs
- RectValueSerializer.cs
- ErrorLog.cs
- GridViewColumnHeader.cs
- Avt.cs
- DataGridRowDetailsEventArgs.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- RuleElement.cs
- VarRemapper.cs
- Debug.cs
- Object.cs
- ConstructorExpr.cs
- TouchesOverProperty.cs
- ObjectListFieldsPage.cs
- Error.cs
- TraceSection.cs
- WebBaseEventKeyComparer.cs
- TableLayoutRowStyleCollection.cs
- ImageAnimator.cs
- EntityDataSourceChangingEventArgs.cs
- TextSpan.cs
- TextEditorTyping.cs
- Int64Converter.cs
- ScriptResourceAttribute.cs
- QueueAccessMode.cs
- ClientEventManager.cs
- GridSplitter.cs
- PropertyEmitter.cs
- StateFinalizationDesigner.cs
- OracleDateTime.cs
- RequestUriProcessor.cs
- WindowsSlider.cs
- ViewKeyConstraint.cs
- BoolExpression.cs
- Bidi.cs
- DataGridDetailsPresenter.cs
- SecurityPermission.cs
- InvalidEnumArgumentException.cs
- XmlHierarchicalEnumerable.cs
- AssertFilter.cs
- PreviewKeyDownEventArgs.cs
- Util.cs
- ServiceDocumentFormatter.cs
- VSWCFServiceContractGenerator.cs