Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntityDesign / Design / System / Data / Entity / Design / PluralizationService / BidirectionalDictionary.cs / 1305376 / BidirectionalDictionary.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Globalization; namespace System.Data.Entity.Design.PluralizationServices { ////// This class provide service for both the singularization and pluralization, it takes the word pairs /// in the ctor following the rules that the first one is singular and the second one is plural. /// internal class BidirectionalDictionary{ internal Dictionary FirstToSecondDictionary { get; set; } internal Dictionary SecondToFirstDictionary { get; set; } internal BidirectionalDictionary() { this.FirstToSecondDictionary = new Dictionary (); this.SecondToFirstDictionary = new Dictionary (); } internal BidirectionalDictionary(Dictionary firstToSecondDictionary) : this() { foreach (var key in firstToSecondDictionary.Keys) { this.AddValue(key, firstToSecondDictionary[key]); } } internal virtual bool ExistsInFirst(TFirst value) { if (this.FirstToSecondDictionary.ContainsKey(value)) { return true; } return false; } internal virtual bool ExistsInSecond(TSecond value) { if (this.SecondToFirstDictionary.ContainsKey(value)) { return true; } return false; } internal virtual TSecond GetSecondValue(TFirst value) { if (this.ExistsInFirst(value)) { return this.FirstToSecondDictionary[value]; } else { return default(TSecond); } } internal virtual TFirst GetFirstValue(TSecond value) { if (this.ExistsInSecond(value)) { return this.SecondToFirstDictionary[value]; } else { return default(TFirst); } } internal void AddValue(TFirst firstValue, TSecond secondValue) { this.FirstToSecondDictionary.Add(firstValue, secondValue); if (!this.SecondToFirstDictionary.ContainsKey(secondValue)) { this.SecondToFirstDictionary.Add(secondValue, firstValue); } } } internal class StringBidirectionalDictionary : BidirectionalDictionary { internal StringBidirectionalDictionary() : base() { } internal StringBidirectionalDictionary(Dictionary firstToSecondDictionary) : base(firstToSecondDictionary) { } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] internal override bool ExistsInFirst(string value) { return base.ExistsInFirst(value.ToLowerInvariant()); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] internal override bool ExistsInSecond(string value) { return base.ExistsInSecond(value.ToLowerInvariant()); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] internal override string GetFirstValue(string value) { return base.GetFirstValue(value.ToLowerInvariant()); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] internal override string GetSecondValue(string value) { return base.GetSecondValue(value.ToLowerInvariant()); } } } // 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.Linq; using System.Text; using System.Globalization; namespace System.Data.Entity.Design.PluralizationServices { ////// This class provide service for both the singularization and pluralization, it takes the word pairs /// in the ctor following the rules that the first one is singular and the second one is plural. /// internal class BidirectionalDictionary{ internal Dictionary FirstToSecondDictionary { get; set; } internal Dictionary SecondToFirstDictionary { get; set; } internal BidirectionalDictionary() { this.FirstToSecondDictionary = new Dictionary (); this.SecondToFirstDictionary = new Dictionary (); } internal BidirectionalDictionary(Dictionary firstToSecondDictionary) : this() { foreach (var key in firstToSecondDictionary.Keys) { this.AddValue(key, firstToSecondDictionary[key]); } } internal virtual bool ExistsInFirst(TFirst value) { if (this.FirstToSecondDictionary.ContainsKey(value)) { return true; } return false; } internal virtual bool ExistsInSecond(TSecond value) { if (this.SecondToFirstDictionary.ContainsKey(value)) { return true; } return false; } internal virtual TSecond GetSecondValue(TFirst value) { if (this.ExistsInFirst(value)) { return this.FirstToSecondDictionary[value]; } else { return default(TSecond); } } internal virtual TFirst GetFirstValue(TSecond value) { if (this.ExistsInSecond(value)) { return this.SecondToFirstDictionary[value]; } else { return default(TFirst); } } internal void AddValue(TFirst firstValue, TSecond secondValue) { this.FirstToSecondDictionary.Add(firstValue, secondValue); if (!this.SecondToFirstDictionary.ContainsKey(secondValue)) { this.SecondToFirstDictionary.Add(secondValue, firstValue); } } } internal class StringBidirectionalDictionary : BidirectionalDictionary { internal StringBidirectionalDictionary() : base() { } internal StringBidirectionalDictionary(Dictionary firstToSecondDictionary) : base(firstToSecondDictionary) { } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] internal override bool ExistsInFirst(string value) { return base.ExistsInFirst(value.ToLowerInvariant()); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] internal override bool ExistsInSecond(string value) { return base.ExistsInSecond(value.ToLowerInvariant()); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] internal override string GetFirstValue(string value) { return base.GetFirstValue(value.ToLowerInvariant()); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")] internal override string GetSecondValue(string value) { return base.GetSecondValue(value.ToLowerInvariant()); } } } // 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
- TextEditor.cs
- SpeechDetectedEventArgs.cs
- MemberDescriptor.cs
- BamlMapTable.cs
- SettingsSection.cs
- Documentation.cs
- PropertyGeneratedEventArgs.cs
- SqlDataSourceCache.cs
- XmlSchema.cs
- GrammarBuilder.cs
- LogicalExpressionEditor.cs
- DeploymentSectionCache.cs
- XpsResourcePolicy.cs
- CompareInfo.cs
- CapabilitiesSection.cs
- PrintPageEvent.cs
- ManipulationStartedEventArgs.cs
- TagPrefixCollection.cs
- CssClassPropertyAttribute.cs
- BinaryWriter.cs
- SplashScreenNativeMethods.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- ConsoleKeyInfo.cs
- BaseResourcesBuildProvider.cs
- Pen.cs
- TypeDelegator.cs
- PolicyReader.cs
- PathStreamGeometryContext.cs
- SplineKeyFrames.cs
- PropertyChangingEventArgs.cs
- SortQuery.cs
- Speller.cs
- EFTableProvider.cs
- PlanCompilerUtil.cs
- TextElement.cs
- PersonalizationProviderHelper.cs
- SecurityTokenSerializer.cs
- CompilationUtil.cs
- MetaTableHelper.cs
- DescendantQuery.cs
- GACIdentityPermission.cs
- ConditionalAttribute.cs
- Nodes.cs
- BuildProvidersCompiler.cs
- ProtocolException.cs
- DependsOnAttribute.cs
- SimplePropertyEntry.cs
- InvalidComObjectException.cs
- PopupControlService.cs
- LambdaCompiler.ControlFlow.cs
- XsltException.cs
- ParameterBinding.cs
- ImageSourceValueSerializer.cs
- OleDbCommandBuilder.cs
- Site.cs
- SharedUtils.cs
- Int64Storage.cs
- VBIdentifierTrimConverter.cs
- MDIWindowDialog.cs
- BooleanAnimationUsingKeyFrames.cs
- SchemaDeclBase.cs
- DocumentXPathNavigator.cs
- RIPEMD160.cs
- DuplexSecurityProtocolFactory.cs
- AnnotationDocumentPaginator.cs
- BamlLocalizableResource.cs
- FormViewDeleteEventArgs.cs
- SqlConnectionHelper.cs
- GridSplitterAutomationPeer.cs
- CommandBinding.cs
- BigInt.cs
- FloaterParagraph.cs
- VirtualizingStackPanel.cs
- InnerItemCollectionView.cs
- AttachedAnnotation.cs
- MultipartIdentifier.cs
- InvalidCastException.cs
- RowsCopiedEventArgs.cs
- SqlDataSourceEnumerator.cs
- DataTemplateSelector.cs
- SchemaAttDef.cs
- recordstatescratchpad.cs
- WebEvents.cs
- NavigationHelper.cs
- BufferedGraphicsContext.cs
- WorkflowApplication.cs
- MetadataFile.cs
- AnnotationComponentChooser.cs
- safex509handles.cs
- CodePropertyReferenceExpression.cs
- TrackingMemoryStream.cs
- CheckBoxBaseAdapter.cs
- XPathSingletonIterator.cs
- contentDescriptor.cs
- BuildProviderUtils.cs
- designeractionbehavior.cs
- ProfileProvider.cs
- CodeParameterDeclarationExpression.cs
- IProvider.cs
- GeneralTransform3DTo2DTo3D.cs