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
- MenuItemCollectionEditor.cs
- EmptyControlCollection.cs
- Timer.cs
- MembershipAdapter.cs
- RotateTransform3D.cs
- AmbientLight.cs
- WebZone.cs
- RijndaelManaged.cs
- wmiprovider.cs
- ColorTranslator.cs
- DropDownList.cs
- SystemTcpStatistics.cs
- ImageCreator.cs
- NetworkAddressChange.cs
- EnumValidator.cs
- ByteStream.cs
- Attribute.cs
- LocatorManager.cs
- DiscardableAttribute.cs
- FileDialogCustomPlace.cs
- SettingsPropertyCollection.cs
- ColorPalette.cs
- FlowchartSizeFeature.cs
- IdentityElement.cs
- TimeoutTimer.cs
- WizardStepBase.cs
- Int32Converter.cs
- _emptywebproxy.cs
- DataObjectAttribute.cs
- StrongName.cs
- BoundField.cs
- StateValidator.cs
- ActivityBindForm.Designer.cs
- SemaphoreSecurity.cs
- DBPropSet.cs
- MulticastNotSupportedException.cs
- HashAlgorithm.cs
- IImplicitResourceProvider.cs
- ScrollableControlDesigner.cs
- GridViewDesigner.cs
- AppSettingsExpressionBuilder.cs
- AdCreatedEventArgs.cs
- ScriptBehaviorDescriptor.cs
- DbConnectionStringCommon.cs
- BinaryObjectInfo.cs
- XmlCodeExporter.cs
- OperatingSystem.cs
- BindingWorker.cs
- TextMarkerSource.cs
- HistoryEventArgs.cs
- SubclassTypeValidator.cs
- SecureConversationServiceCredential.cs
- SmiEventSink_DeferedProcessing.cs
- PointConverter.cs
- BreakSafeBase.cs
- CheckedPointers.cs
- ListSourceHelper.cs
- ArrayExtension.cs
- URL.cs
- XmlSchemaInclude.cs
- InputReport.cs
- OperationResponse.cs
- AxHost.cs
- RuleSetBrowserDialog.cs
- TraceListener.cs
- WmlLiteralTextAdapter.cs
- PermissionToken.cs
- SimpleWorkerRequest.cs
- ECDiffieHellmanPublicKey.cs
- WebPartTransformer.cs
- TreeNodeConverter.cs
- BuildResultCache.cs
- BinaryMethodMessage.cs
- ContractMapping.cs
- ImpersonateTokenRef.cs
- EnumBuilder.cs
- WebPartConnectionsConnectVerb.cs
- followingquery.cs
- DataListItem.cs
- ObjectQuery.cs
- ExpressionBindingCollection.cs
- EpmSourcePathSegment.cs
- GPRECTF.cs
- CommandExpr.cs
- ScrollPattern.cs
- EntryWrittenEventArgs.cs
- DataListComponentEditor.cs
- DescendantBaseQuery.cs
- UIHelper.cs
- SafeArrayTypeMismatchException.cs
- XmlSchemaIdentityConstraint.cs
- DoubleAverageAggregationOperator.cs
- EventManager.cs
- TypeToken.cs
- ChangeProcessor.cs
- ToolboxItemAttribute.cs
- DiagnosticTraceSource.cs
- ClrPerspective.cs
- DataContractJsonSerializerOperationFormatter.cs
- WindowsButton.cs