Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Common / Utils / Boolean / IdentifierService.cs / 1599186 / IdentifierService.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Collections.ObjectModel; using System.Globalization; using System.Linq; using System.Runtime.CompilerServices; namespace System.Data.Common.Utils.Boolean { ////// Services related to different identifier types for Boolean expressions. /// internal abstract class IdentifierService{ #region Static members internal static readonly IdentifierService Instance = GetIdentifierService(); [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] private static IdentifierService GetIdentifierService() { Type identifierType = typeof(T_Identifier); if (identifierType.IsGenericType && identifierType.GetGenericTypeDefinition() == typeof(DomainConstraint<,>)) { // initialize a domain constraint literal service Type[] genericArguments = identifierType.GetGenericArguments(); Type variableType = genericArguments[0]; Type elementType = genericArguments[1]; return (IdentifierService )Activator.CreateInstance( typeof(DomainConstraintIdentifierService<,>).MakeGenericType(identifierType, variableType, elementType)); } else { // initialize a generic literal service for all other identifier types return new GenericIdentifierService(); } } #endregion #region Constructors private IdentifierService() { } #endregion #region Service methods /// /// Returns negation of the given literal. /// internal abstract LiteralNegateLiteral(Literal literal); /// /// Creates a new conversion context. /// internal abstract ConversionContextCreateConversionContext(); /// /// Performs local simplification appropriate to the current identifier. /// internal abstract BoolExprLocalSimplify(BoolExpr expression); #endregion private class GenericIdentifierService : IdentifierService { internal override Literal NegateLiteral(Literal literal) { // just invert the sign return new Literal (literal.Term, !literal.IsTermPositive); } internal override ConversionContext CreateConversionContext() { return new GenericConversionContext (); } internal override BoolExpr LocalSimplify(BoolExpr expression) { return expression.Accept(Simplifier .Instance); } } private class DomainConstraintIdentifierService : IdentifierService > { internal override Literal > NegateLiteral(Literal > literal) { // negate the literal by inverting the range, rather than changing the sign // of the literal TermExpr > term = new TermExpr >( literal.Term.Identifier.InvertDomainConstraint()); return new Literal >(term, literal.IsTermPositive); } internal override ConversionContext > CreateConversionContext() { return new DomainConstraintConversionContext (); } internal override BoolExpr > LocalSimplify(BoolExpr > expression) { expression = NegationPusher.EliminateNot (expression); return expression.Accept(Simplifier >.Instance); } } } } // 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.Text; using System.Diagnostics; using System.Collections.ObjectModel; using System.Globalization; using System.Linq; using System.Runtime.CompilerServices; namespace System.Data.Common.Utils.Boolean { ////// Services related to different identifier types for Boolean expressions. /// internal abstract class IdentifierService{ #region Static members internal static readonly IdentifierService Instance = GetIdentifierService(); [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] private static IdentifierService GetIdentifierService() { Type identifierType = typeof(T_Identifier); if (identifierType.IsGenericType && identifierType.GetGenericTypeDefinition() == typeof(DomainConstraint<,>)) { // initialize a domain constraint literal service Type[] genericArguments = identifierType.GetGenericArguments(); Type variableType = genericArguments[0]; Type elementType = genericArguments[1]; return (IdentifierService )Activator.CreateInstance( typeof(DomainConstraintIdentifierService<,>).MakeGenericType(identifierType, variableType, elementType)); } else { // initialize a generic literal service for all other identifier types return new GenericIdentifierService(); } } #endregion #region Constructors private IdentifierService() { } #endregion #region Service methods /// /// Returns negation of the given literal. /// internal abstract LiteralNegateLiteral(Literal literal); /// /// Creates a new conversion context. /// internal abstract ConversionContextCreateConversionContext(); /// /// Performs local simplification appropriate to the current identifier. /// internal abstract BoolExprLocalSimplify(BoolExpr expression); #endregion private class GenericIdentifierService : IdentifierService { internal override Literal NegateLiteral(Literal literal) { // just invert the sign return new Literal (literal.Term, !literal.IsTermPositive); } internal override ConversionContext CreateConversionContext() { return new GenericConversionContext (); } internal override BoolExpr LocalSimplify(BoolExpr expression) { return expression.Accept(Simplifier .Instance); } } private class DomainConstraintIdentifierService : IdentifierService > { internal override Literal > NegateLiteral(Literal > literal) { // negate the literal by inverting the range, rather than changing the sign // of the literal TermExpr > term = new TermExpr >( literal.Term.Identifier.InvertDomainConstraint()); return new Literal >(term, literal.IsTermPositive); } internal override ConversionContext > CreateConversionContext() { return new DomainConstraintConversionContext (); } internal override BoolExpr > LocalSimplify(BoolExpr > expression) { expression = NegationPusher.EliminateNot (expression); return expression.Accept(Simplifier >.Instance); } } } } // 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
- DeclarativeCatalogPart.cs
- XmlNamedNodeMap.cs
- GenericIdentity.cs
- Application.cs
- SecurityContextSecurityTokenParameters.cs
- FixedSOMTableCell.cs
- WebPartConnectionsConfigureVerb.cs
- StatusBarItemAutomationPeer.cs
- DllHostedComPlusServiceHost.cs
- Models.cs
- InputBuffer.cs
- GeometryDrawing.cs
- EventProvider.cs
- WebPartEventArgs.cs
- ToolTipService.cs
- ExponentialEase.cs
- BuildProviderCollection.cs
- KeyedHashAlgorithm.cs
- StrongTypingException.cs
- ResourceManager.cs
- HttpCookieCollection.cs
- VarRemapper.cs
- BulletedListEventArgs.cs
- KoreanCalendar.cs
- RepeaterItem.cs
- ContainerFilterService.cs
- ToggleButtonAutomationPeer.cs
- DateTimePicker.cs
- ComponentSerializationService.cs
- MultiSelector.cs
- HostSecurityManager.cs
- BindingListCollectionView.cs
- PrivilegedConfigurationManager.cs
- DataGridViewAdvancedBorderStyle.cs
- ComponentResourceKeyConverter.cs
- SuppressMergeCheckAttribute.cs
- BooleanKeyFrameCollection.cs
- ValidationRuleCollection.cs
- AssemblyResourceLoader.cs
- BaseConfigurationRecord.cs
- IIS7WorkerRequest.cs
- TypefaceMap.cs
- MessageRpc.cs
- WindowsGraphicsWrapper.cs
- FreeFormDesigner.cs
- GlyphShapingProperties.cs
- OleDbDataAdapter.cs
- SecurityMode.cs
- remotingproxy.cs
- WeakRefEnumerator.cs
- CodeVariableDeclarationStatement.cs
- PerfCounters.cs
- TokenizerHelper.cs
- Timer.cs
- SystemUnicastIPAddressInformation.cs
- OdbcDataReader.cs
- ColorKeyFrameCollection.cs
- StorageTypeMapping.cs
- ModelItemCollection.cs
- BinaryNode.cs
- DockAndAnchorLayout.cs
- GroupQuery.cs
- DriveInfo.cs
- EntityWithKeyStrategy.cs
- DesignerActionList.cs
- MenuScrollingVisibilityConverter.cs
- Window.cs
- WebBrowsableAttribute.cs
- SiteMapNodeItem.cs
- XmlSecureResolver.cs
- XmlSiteMapProvider.cs
- GraphicsContainer.cs
- ModelTreeEnumerator.cs
- Color.cs
- DbConnectionPoolIdentity.cs
- ReadOnlyDictionary.cs
- EraserBehavior.cs
- PreservationFileWriter.cs
- baseshape.cs
- DropDownButton.cs
- HostingEnvironmentSection.cs
- CatalogZone.cs
- FatalException.cs
- TypeDescriptorContext.cs
- PropertyPathWorker.cs
- CallbackValidator.cs
- ImageDrawing.cs
- CompilerErrorCollection.cs
- HttpCachePolicyElement.cs
- AnimationException.cs
- ScrollChangedEventArgs.cs
- StreamInfo.cs
- Blend.cs
- StoryFragments.cs
- SessionSwitchEventArgs.cs
- IndependentlyAnimatedPropertyMetadata.cs
- DefaultCommandConverter.cs
- SoapBinding.cs
- DocumentPageViewAutomationPeer.cs
- ManagementScope.cs