Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / DictionaryItemsCollection.cs / 1305376 / DictionaryItemsCollection.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Presentation { using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime; class DictionaryItemsCollection: Collection > { IDictionary dictionary; public DictionaryItemsCollection(object dictionary) { this.dictionary = dictionary as IDictionary ; Fx.Assert(this.dictionary != null, "dictionary should be instantiated"); foreach (KeyValuePair kvpair in this.dictionary) { ModelItemKeyValuePair item = new ModelItemKeyValuePair (kvpair.Key, kvpair.Value); item.collection = this; base.InsertItem(this.Count, item); } } internal void PostUpdateKey() { this.UpdateDictionary(); } internal void PreUpdateKey(TKey oldKey, TKey newKey) { this.dictionary.Remove(oldKey); if (this.dictionary.ContainsKey(newKey)) { this.UpdateDictionary(); throw FxTrace.Exception.AsError(new ArgumentException(SR.DuplicateKey)); } } internal void UpdateValue(TKey key, TValue value) { this.dictionary[key] = value; } protected override void ClearItems() { this.dictionary.Clear(); base.ClearItems(); } protected override void InsertItem(int index, ModelItemKeyValuePair item) { if (item == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("item")); } if (this.dictionary.ContainsKey(item.Key)) { throw FxTrace.Exception.AsError(new ArgumentException(SR.DuplicateKey)); } item.collection = this; base.InsertItem(index, item); this.UpdateDictionary(); } protected override void RemoveItem(int index) { ModelItemKeyValuePair item = this[index]; Fx.Assert(item != null, "Item should not be null."); this.dictionary.Remove(item.Key); base.RemoveItem(index); } protected override void SetItem(int index, ModelItemKeyValuePair item) { if (item == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("item")); } item.collection = this; ModelItemKeyValuePair oldItem = this[index]; Fx.Assert(oldItem != null, "Item should not be null."); this.PreUpdateKey(oldItem.Key, item.Key); base.SetItem(index, item); this.PostUpdateKey(); } void UpdateDictionary() { // Make sure the order of KVPairs in the dictionary is the same as the order of items in the collection this.dictionary.Clear(); foreach (ModelItemKeyValuePair item in this) { this.dictionary.Add(new KeyValuePair (item.Key, item.Value)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Presentation { using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime; class DictionaryItemsCollection : Collection > { IDictionary dictionary; public DictionaryItemsCollection(object dictionary) { this.dictionary = dictionary as IDictionary ; Fx.Assert(this.dictionary != null, "dictionary should be instantiated"); foreach (KeyValuePair kvpair in this.dictionary) { ModelItemKeyValuePair item = new ModelItemKeyValuePair (kvpair.Key, kvpair.Value); item.collection = this; base.InsertItem(this.Count, item); } } internal void PostUpdateKey() { this.UpdateDictionary(); } internal void PreUpdateKey(TKey oldKey, TKey newKey) { this.dictionary.Remove(oldKey); if (this.dictionary.ContainsKey(newKey)) { this.UpdateDictionary(); throw FxTrace.Exception.AsError(new ArgumentException(SR.DuplicateKey)); } } internal void UpdateValue(TKey key, TValue value) { this.dictionary[key] = value; } protected override void ClearItems() { this.dictionary.Clear(); base.ClearItems(); } protected override void InsertItem(int index, ModelItemKeyValuePair item) { if (item == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("item")); } if (this.dictionary.ContainsKey(item.Key)) { throw FxTrace.Exception.AsError(new ArgumentException(SR.DuplicateKey)); } item.collection = this; base.InsertItem(index, item); this.UpdateDictionary(); } protected override void RemoveItem(int index) { ModelItemKeyValuePair item = this[index]; Fx.Assert(item != null, "Item should not be null."); this.dictionary.Remove(item.Key); base.RemoveItem(index); } protected override void SetItem(int index, ModelItemKeyValuePair item) { if (item == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("item")); } item.collection = this; ModelItemKeyValuePair oldItem = this[index]; Fx.Assert(oldItem != null, "Item should not be null."); this.PreUpdateKey(oldItem.Key, item.Key); base.SetItem(index, item); this.PostUpdateKey(); } void UpdateDictionary() { // Make sure the order of KVPairs in the dictionary is the same as the order of items in the collection this.dictionary.Clear(); foreach (ModelItemKeyValuePair item in this) { this.dictionary.Add(new KeyValuePair (item.Key, item.Value)); } } } } // 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
- MissingMemberException.cs
- CodeComment.cs
- TimeoutHelper.cs
- LineVisual.cs
- Inflater.cs
- Clock.cs
- CodeDirectionExpression.cs
- HttpRequestWrapper.cs
- AutomationEvent.cs
- ColumnHeaderCollectionEditor.cs
- GeneralTransform3DTo2D.cs
- ResXDataNode.cs
- ImageBrush.cs
- BatchWriter.cs
- SerializationAttributes.cs
- SspiHelper.cs
- MetricEntry.cs
- ForceCopyBuildProvider.cs
- ProcessModelSection.cs
- Switch.cs
- FileDialogPermission.cs
- DataGridViewRowContextMenuStripNeededEventArgs.cs
- QilBinary.cs
- CopyCodeAction.cs
- OraclePermissionAttribute.cs
- SymbolEqualComparer.cs
- DrawingVisual.cs
- FixedBufferAttribute.cs
- CodeDirectionExpression.cs
- SafeCoTaskMem.cs
- SrgsRulesCollection.cs
- SecurityDescriptor.cs
- AssemblyAttributesGoHere.cs
- CustomCredentialPolicy.cs
- BaseCAMarshaler.cs
- VScrollBar.cs
- HwndSubclass.cs
- BulletedList.cs
- SystemIPGlobalStatistics.cs
- ObjectDataSourceMethodEventArgs.cs
- OracleDataReader.cs
- MenuItemStyle.cs
- WindowsListViewScroll.cs
- ItemsPresenter.cs
- DtdParser.cs
- BaseDataBoundControlDesigner.cs
- TemplateXamlTreeBuilder.cs
- LoginUtil.cs
- SoapHeaderAttribute.cs
- ReflectionTypeLoadException.cs
- bidPrivateBase.cs
- NumberFunctions.cs
- DragEventArgs.cs
- BufferedGraphicsContext.cs
- RevocationPoint.cs
- storepermission.cs
- CFGGrammar.cs
- COM2EnumConverter.cs
- AggregateNode.cs
- DateTimePicker.cs
- ModelTreeEnumerator.cs
- PropertyEmitter.cs
- CacheSection.cs
- FocusWithinProperty.cs
- SqlAliasesReferenced.cs
- ObjectResult.cs
- ManagedIStream.cs
- ClientFormsAuthenticationCredentials.cs
- FunctionQuery.cs
- WebPartHeaderCloseVerb.cs
- UniqueCodeIdentifierScope.cs
- TextSearch.cs
- ContractDescription.cs
- DataViewManagerListItemTypeDescriptor.cs
- MenuScrollingVisibilityConverter.cs
- Axis.cs
- InstancePersistenceException.cs
- CodeCommentStatementCollection.cs
- PointHitTestResult.cs
- HwndProxyElementProvider.cs
- StateWorkerRequest.cs
- X509ClientCertificateAuthenticationElement.cs
- MethodRental.cs
- XmlDictionaryReaderQuotas.cs
- DataContractJsonSerializer.cs
- OptimalBreakSession.cs
- DataGridHelper.cs
- ToolTipAutomationPeer.cs
- MouseCaptureWithinProperty.cs
- RepeaterItemEventArgs.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- AsyncCompletedEventArgs.cs
- Rectangle.cs
- ColumnCollection.cs
- StylusPointPropertyUnit.cs
- PasswordPropertyTextAttribute.cs
- RotateTransform.cs
- TypeDescriptionProvider.cs
- DataColumnCollection.cs
- DeleteHelper.cs