Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Map / ViewGeneration / CqlGeneration / CqlIdentifiers.cs / 1305376 / CqlIdentifiers.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Data.Common.Utils; using System.Text; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; namespace System.Data.Mapping.ViewGeneration.Structures { // This class is responsible for ensuring unique aliases for _from0, etc // and block aliases T, T0, T1, etc internal class CqlIdentifiers : InternalBase { #region Constructor internal CqlIdentifiers() { m_identifiers = new Set(StringComparer.Ordinal); } #endregion #region Fields private Set m_identifiers; #endregion #region Methods // effects: Given a number, returns _from if it does not clashes with // any identifier, else returns _from_ _ where is the first number from 0 // where there is no clash internal string GetFromVariable(int num) { return GetNonConflictingName("_from", num); } // effects: Given a number, returns T if it does not clashes with // any identifier, else returns T_ _ where is the first number from 0 // where there is no clash internal string GetBlockAlias(int num) { return GetNonConflictingName("T", num); } // effects: Given a number, returns T if it does not clashes with // any identifier, else returns T_ where is the first number from 0 // where there is no clash internal string GetBlockAlias() { return GetNonConflictingName("T", -1); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] internal void AddIdentifier(string identifier) { m_identifiers.Add(identifier.ToLower(CultureInfo.InvariantCulture)); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] private string GetNonConflictingName(string prefix, int number) { // Do a case sensitive search but return the string that uses the // original prefix string result = number < 0 ? prefix : StringUtil.FormatInvariant("{0}{1}", prefix, number); // Check if the prefix exists or not if (m_identifiers.Contains(result.ToLower(CultureInfo.InvariantCulture)) == false) { return result; } // Go through integers and find the first one that does not clash for (int count = 0; count < int.MaxValue; count++) { if (number < 0) { result = StringUtil.FormatInvariant("{0}_{1}", prefix, count); } else { result = StringUtil.FormatInvariant("{0}_{1}_{2}", prefix, count, number); } if (m_identifiers.Contains(result.ToLower(CultureInfo.InvariantCulture)) == false) { return result; } } Debug.Fail("Found no unique _from till MaxValue?"); return null; } internal override void ToCompactString(StringBuilder builder) { m_identifiers.ToCompactString(builder); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Data.Common.Utils; using System.Text; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; namespace System.Data.Mapping.ViewGeneration.Structures { // This class is responsible for ensuring unique aliases for _from0, etc // and block aliases T, T0, T1, etc internal class CqlIdentifiers : InternalBase { #region Constructor internal CqlIdentifiers() { m_identifiers = new Set(StringComparer.Ordinal); } #endregion #region Fields private Set m_identifiers; #endregion #region Methods // effects: Given a number, returns _from if it does not clashes with // any identifier, else returns _from_ _ where is the first number from 0 // where there is no clash internal string GetFromVariable(int num) { return GetNonConflictingName("_from", num); } // effects: Given a number, returns T if it does not clashes with // any identifier, else returns T_ _ where is the first number from 0 // where there is no clash internal string GetBlockAlias(int num) { return GetNonConflictingName("T", num); } // effects: Given a number, returns T if it does not clashes with // any identifier, else returns T_ where is the first number from 0 // where there is no clash internal string GetBlockAlias() { return GetNonConflictingName("T", -1); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] internal void AddIdentifier(string identifier) { m_identifiers.Add(identifier.ToLower(CultureInfo.InvariantCulture)); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] private string GetNonConflictingName(string prefix, int number) { // Do a case sensitive search but return the string that uses the // original prefix string result = number < 0 ? prefix : StringUtil.FormatInvariant("{0}{1}", prefix, number); // Check if the prefix exists or not if (m_identifiers.Contains(result.ToLower(CultureInfo.InvariantCulture)) == false) { return result; } // Go through integers and find the first one that does not clash for (int count = 0; count < int.MaxValue; count++) { if (number < 0) { result = StringUtil.FormatInvariant("{0}_{1}", prefix, count); } else { result = StringUtil.FormatInvariant("{0}_{1}_{2}", prefix, count, number); } if (m_identifiers.Contains(result.ToLower(CultureInfo.InvariantCulture)) == false) { return result; } } Debug.Fail("Found no unique _from till MaxValue?"); return null; } internal override void ToCompactString(StringBuilder builder) { m_identifiers.ToCompactString(builder); } #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
- CodeEventReferenceExpression.cs
- SecurityDocument.cs
- SystemUnicastIPAddressInformation.cs
- SqlCacheDependencyDatabase.cs
- UnknownWrapper.cs
- DataGridPageChangedEventArgs.cs
- MenuItemBindingCollection.cs
- StringPropertyBuilder.cs
- HtmlTitle.cs
- FamilyTypefaceCollection.cs
- ExtractedStateEntry.cs
- Accessible.cs
- NeutralResourcesLanguageAttribute.cs
- SecUtil.cs
- AutoResizedEvent.cs
- PeerObject.cs
- DetailsViewInsertEventArgs.cs
- InitiatorSessionSymmetricTransportSecurityProtocol.cs
- FaultReasonText.cs
- DrawingContext.cs
- AssemblyUtil.cs
- Rfc2898DeriveBytes.cs
- Stroke2.cs
- XmlSchemaProviderAttribute.cs
- NameTable.cs
- Int32EqualityComparer.cs
- WindowsListBox.cs
- Model3DCollection.cs
- AbstractDataSvcMapFileLoader.cs
- PeerEndPoint.cs
- util.cs
- ServiceAuthorizationManager.cs
- Help.cs
- ExceptionUtil.cs
- GeneralTransformGroup.cs
- ChildDocumentBlock.cs
- ClientUtils.cs
- XamlHttpHandlerFactory.cs
- OrderedDictionaryStateHelper.cs
- DomNameTable.cs
- Visitors.cs
- GZipStream.cs
- SqlDataSourceQueryEditor.cs
- TypeTypeConverter.cs
- ZoomPercentageConverter.cs
- FtpWebResponse.cs
- StringResourceManager.cs
- BrowserDefinition.cs
- FormsAuthenticationModule.cs
- ChannelSinkStacks.cs
- TextServicesManager.cs
- WebHttpDispatchOperationSelector.cs
- ShutDownListener.cs
- configsystem.cs
- _SslStream.cs
- ToolBarOverflowPanel.cs
- StateInitializationDesigner.cs
- CustomAssemblyResolver.cs
- _AutoWebProxyScriptWrapper.cs
- xamlnodes.cs
- GAC.cs
- ApplicationSecurityInfo.cs
- Preprocessor.cs
- Transform.cs
- DBCSCodePageEncoding.cs
- GACIdentityPermission.cs
- QilInvokeLateBound.cs
- DispatchWrapper.cs
- TextEditorSpelling.cs
- MetadataItem.cs
- MetadataItem_Static.cs
- VectorAnimationUsingKeyFrames.cs
- ExpandableObjectConverter.cs
- TouchesCapturedWithinProperty.cs
- FileUtil.cs
- FixedTextView.cs
- LinqDataSourceView.cs
- CodeTypeDeclarationCollection.cs
- CodeDomConfigurationHandler.cs
- DispatchOperationRuntime.cs
- WrapPanel.cs
- ComIntegrationManifestGenerator.cs
- XmlCodeExporter.cs
- ThemeInfoAttribute.cs
- LoadItemsEventArgs.cs
- CompressionTracing.cs
- XslTransform.cs
- DefaultSerializationProviderAttribute.cs
- Selection.cs
- TCPListener.cs
- AssemblyInfo.cs
- EventMappingSettings.cs
- DebugHandleTracker.cs
- ResourcesGenerator.cs
- DoubleLinkList.cs
- PenContexts.cs
- ProcessModelInfo.cs
- ClientSponsor.cs
- BaseCollection.cs
- DataGridTablesFactory.cs