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
- HandleRef.cs
- MimeMapping.cs
- SourceElementsCollection.cs
- FontFamilyIdentifier.cs
- XmlSortKey.cs
- FileRecordSequenceCompletedAsyncResult.cs
- XmlSecureResolver.cs
- BitStream.cs
- TextRangeSerialization.cs
- PackageRelationshipSelector.cs
- AnnotationHighlightLayer.cs
- Style.cs
- MatrixUtil.cs
- DriveInfo.cs
- ParseNumbers.cs
- DataGridViewImageColumn.cs
- AuthorizationRuleCollection.cs
- NotifyCollectionChangedEventArgs.cs
- QueryLifecycle.cs
- ListViewUpdatedEventArgs.cs
- DataRecordInfo.cs
- BlurBitmapEffect.cs
- arclist.cs
- ExpressionBindingCollection.cs
- OLEDB_Util.cs
- DelayedRegex.cs
- ToolStripProgressBar.cs
- SerialPinChanges.cs
- SemaphoreSecurity.cs
- Frame.cs
- Serializer.cs
- FileSystemInfo.cs
- XmlQueryOutput.cs
- InnerItemCollectionView.cs
- WebPartZoneBase.cs
- ObjectManager.cs
- RootProjectionNode.cs
- QilName.cs
- ControlEvent.cs
- CdpEqualityComparer.cs
- GridViewRow.cs
- RIPEMD160Managed.cs
- FileDialogCustomPlacesCollection.cs
- PixelFormat.cs
- UnregisterInfo.cs
- ImpersonationContext.cs
- ActivityBindForm.cs
- DataGridViewAccessibleObject.cs
- XmlTypeMapping.cs
- ParameterCollection.cs
- GraphicsState.cs
- TemplateColumn.cs
- BStrWrapper.cs
- PasswordRecovery.cs
- SortableBindingList.cs
- TrackingRecord.cs
- UrlMappingCollection.cs
- OracleColumn.cs
- TreeChangeInfo.cs
- EdmItemError.cs
- DBConcurrencyException.cs
- ReliableRequestSessionChannel.cs
- HelpKeywordAttribute.cs
- DeleteCardRequest.cs
- ISAPIApplicationHost.cs
- SHA1Managed.cs
- Stackframe.cs
- ReliableMessagingHelpers.cs
- SymbolType.cs
- JoinElimination.cs
- JsonFaultDetail.cs
- InstanceLockQueryResult.cs
- BamlLocalizationDictionary.cs
- Argument.cs
- ShapeTypeface.cs
- CellPartitioner.cs
- ScriptServiceAttribute.cs
- StringCollection.cs
- RegexCompiler.cs
- CompilationRelaxations.cs
- BuildResultCache.cs
- TextBreakpoint.cs
- WebBrowserSiteBase.cs
- PerspectiveCamera.cs
- DtdParser.cs
- TextOnlyOutput.cs
- CustomPopupPlacement.cs
- ProxyGenerator.cs
- Events.cs
- FlowDocumentFormatter.cs
- TextWriterTraceListener.cs
- DataSourceExpressionCollection.cs
- SqlInternalConnection.cs
- ObjectCloneHelper.cs
- InputBinding.cs
- baseaxisquery.cs
- IisTraceListener.cs
- CounterCreationData.cs
- SchemaObjectWriter.cs
- DesignerRegionMouseEventArgs.cs