Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / Base / Interaction / Model / ModelItemDictionary.cs / 1305376 / ModelItemDictionary.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Activities.Presentation.Model { using System.Activities.Presentation.Internal.Properties; using System.Activities.Presentation; using System.Runtime; using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Windows; ////// ModelItemDictionary derives from ModelItem and implements support for a /// dictionary of key/value pairs. Both the keys and values are items. /// /// ModelItemDictionary defines an attached property “Key”, which is adds /// to all items contained in the dictionary. The data type of the Key /// property is “ModelItem” and it is marked as non-browsable and /// non-serializable. /// /// In addition to the Key property, ModelItemDictionary also returns an /// Item property from its properties collection just like ModelItemCollection. /// ModelItemDictionary reuses the ModelProperty defined on ModelItemCollection. /// The value returned is an enumeration of the values in the dictionary. /// The Source property of all items in the dictionary refers to this Item /// property. /// public abstract class ModelItemDictionary : ModelItem, IDictionary, IDictionary, INotifyCollectionChanged { /// /// Creates a new ModelItemDictionary. /// protected ModelItemDictionary() { } ////// Returns the item at the given key. Sets the item at the given /// key to the given value. If there is no item for the given key /// this returns null because null is not a valid item. /// /// ////// if key or value is null. ///if the dictionary is read only and you set a new value. ///if the given key is not in the dictionary. [SuppressMessage("Microsoft.Design", "CA1043:UseIntegralOrStringArgumentForIndexers")] public abstract ModelItem this[ModelItem key] { get; set; } ////// Returns the item at the given key. Sets the item at the given /// key to the given value. If there is no item for the given key /// this returns null because null is not a valid item. /// /// ////// if key or value is null. ///if the dictionary is read only and you set a new value. ///if the given key is not in the dictionary. [SuppressMessage("Microsoft.Design", "CA1043:UseIntegralOrStringArgumentForIndexers")] public abstract ModelItem this[object key] { get; set; } ////// Returns the count of items in the dictionary. /// public abstract int Count { get; } ////// Returns true if the dictionary is a fixed size. /// The default implementation returns true if the /// dictionary is read only. /// protected virtual bool IsFixedSize { get { return IsReadOnly; } } ////// Returns true if the dictionary cannot be modified. /// public abstract bool IsReadOnly { get; } ////// Protected access to ICollection.IsSynchronized. /// protected virtual bool IsSynchronized { get { return false; } } ////// Returns the keys of the collection. The keys are guaranteed to be in /// the same order as the values. The resulting collection is read-only. /// [Fx.Tag.KnownXamlExternalAttribute] public abstract ICollectionKeys { get; } /// /// Protected access to the SyncRoot object used to synchronize /// this collection. The default value returns "this". /// protected virtual object SyncRoot { get { return this; } } ////// Returns the values of the collection. The values are guaranteed to be /// in the same order as the keys. The resulting collection is read-only. /// [Fx.Tag.KnownXamlExternalAttribute] public abstract ICollectionValues { get; } /// /// This event is raised when the contents of this collection change. /// public abstract event NotifyCollectionChangedEventHandler CollectionChanged; ////// Adds the item to the dictionary under the given key. /// /// /// ///if key or value is null. ///if the dictionary is read only. public abstract void Add(ModelItem key, ModelItem value); ////// Adds the value to the dictionary under the given key. This /// will wrap the key and value in an item. It returns the item /// representing the key. /// /// /// ///an item representing the key in the dictionary ///if key or value is null. ///if the dictionary is read only. public abstract ModelItem Add(object key, object value); ////// Clears the contents of the dictionary. /// ///if the dictionary is read only. public abstract void Clear(); ////// Copies into the given array. /// /// /// protected virtual void CopyTo(KeyValuePair[] array, int arrayIndex) { foreach (KeyValuePair kv in this) { array[arrayIndex++] = kv; } } /// /// Returns true if the dictionary contains the given key value pair. /// protected virtual bool Contains(KeyValuePairitem) { ModelItem value; return TryGetValue(item.Key, out value) && value == item.Value; } /// /// Returns true if the dictionary contains the given key. /// /// ////// if key is null. public abstract bool ContainsKey(ModelItem key); ////// Returns true if the dictionary contains the given key. /// /// ////// if key is null. public abstract bool ContainsKey(object key); // // Helper method that verifies that objects can be upcast to // the correct type. // private static ModelItem ConvertType(object value) { try { return (ModelItem)value; } catch (InvalidCastException) { throw FxTrace.Exception.AsError(new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.Error_ArgIncorrectType, "value", typeof(ModelItem).FullName))); } } ////// Returns an enumerator for the items in the dictionary. /// ///[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] public abstract IEnumerator > GetEnumerator(); /// /// Removes the item from the dictionary. This does nothing if the item /// does not exist in the collection. /// /// ///if key is null. ///if the dictionary is read only. public abstract bool Remove(ModelItem key); ////// Removes the item from the dictionary. This does nothing if the item /// does not exist in the collection. /// /// ///if key is null. ///if the dictionary is read only. public abstract bool Remove(object key); ////// Retrieves the value for the given key, or returns false if the /// value can’t be found. /// /// /// ////// if key is null. public abstract bool TryGetValue(ModelItem key, out ModelItem value); ////// Retrieves the value for the given key, or returns false if the /// value can’t be found. /// /// /// ////// if key is null. public abstract bool TryGetValue(object key, out ModelItem value); ////// ModelItemDictionary provides an attached property “Key”, which is adds to /// all items contained in the dictionary. The data type of the Key /// property is “ModelItem”. /// public static readonly DependencyProperty KeyProperty = DependencyProperty.RegisterAttachedReadOnly( "Key", typeof(ModelItem), typeof(ModelItemDictionary), null).DependencyProperty; // IDictionary API is synthesized on top of the generic API. #region IDictionary Members ////// IDictionary Implementation maps back to public API. /// void IDictionary.Add(object key, object value) { Add(key, value); } ////// IDictionary Implementation maps back to public API. /// void IDictionary.Clear() { Clear(); } ////// IDictionary Implementation maps back to public API. /// [SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] bool IDictionary.Contains(object key) { return ContainsKey(key); } ////// IDictionary Implementation maps back to public API. /// IDictionaryEnumerator IDictionary.GetEnumerator() { return new DictionaryEnumerator(GetEnumerator()); } ////// IDictionary Implementation maps back to public API. /// bool IDictionary.IsFixedSize { get { return IsFixedSize; } } ////// IDictionary Implementation maps back to public API. /// bool IDictionary.IsReadOnly { get { return IsReadOnly; } } ////// IDictionary Implementation maps back to public API. /// ICollection IDictionary.Keys { get { object[] keys = new object[Count]; int idx = 0; foreach (KeyValuePairkv in this) { keys[idx++] = kv.Key; } return keys; } } /// /// IDictionary Implementation maps back to public API. /// void IDictionary.Remove(object key) { Remove(key); } ////// IDictionary Implementation maps back to public API. /// ICollection IDictionary.Values { get { object[] values = new object[Count]; int idx = 0; foreach (KeyValuePairkv in this) { values[idx++] = kv.Value; } return values; } } /// /// IDictionary Implementation maps back to public API. /// object IDictionary.this[object key] { get { return this[ConvertType(key)]; } set { this[ConvertType(key)] = ConvertType(value); } } #endregion #region ICollection Members ////// ICollection Implementation maps back to public API. /// void ICollection.CopyTo(Array array, int index) { if (Count > 0) { int len = array.GetLength(0); if (index >= len) { throw FxTrace.Exception.AsError(new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.Error_InvalidArrayIndex, index))); } KeyValuePair[] typedArray = new KeyValuePair [len]; CopyTo(typedArray, index); for (; index < typedArray.Length; index++) { array.SetValue(typedArray[index], index); } } } /// /// ICollection Implementation maps back to public API. /// int ICollection.Count { get { return Count; } } ////// ICollection Implementation maps back to public API. /// bool ICollection.IsSynchronized { get { return IsSynchronized; } } ////// ICollection Implementation maps back to public API. /// object ICollection.SyncRoot { get { return SyncRoot; } } #endregion #region IEnumerable Members ////// IEnumerator Implementation maps back to public API. /// IEnumerator IEnumerable.GetEnumerator() { foreach (KeyValuePairkv in this) { yield return kv; } } #endregion #region ICollection > Members void ICollection >.Add(KeyValuePair item) { Add(item.Key, item.Value); } bool ICollection >.Contains(KeyValuePair item) { return Contains(item); } void ICollection >.CopyTo(KeyValuePair [] array, int arrayIndex) { if (arrayIndex >= array.Length) { throw FxTrace.Exception.AsError(new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.Error_InvalidArrayIndex, arrayIndex))); } CopyTo(array, arrayIndex); } bool ICollection >.Remove(KeyValuePair item) { ModelItem value; if (TryGetValue(item.Key, out value) && value == item.Value) { return Remove(item.Key); } return false; } #endregion // // This is a simple struct that implements a dictionary enumerator, // since this isn't supported in the iterator pattern. // private struct DictionaryEnumerator : IDictionaryEnumerator { private IEnumerator > _real; internal DictionaryEnumerator(IEnumerator > real) { _real = real; } #region IDictionaryEnumerator Members public DictionaryEntry Entry { get { return new DictionaryEntry(_real.Current.Key, _real.Current.Value); } } public object Key { get { return _real.Current.Key; } } public object Value { get { return _real.Current.Value; } } #endregion #region IEnumerator Members public object Current { get { return Entry; } } public bool MoveNext() { return _real.MoveNext(); } public void Reset() { _real.Reset(); } #endregion } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Activities.Presentation.Model { using System.Activities.Presentation.Internal.Properties; using System.Activities.Presentation; using System.Runtime; using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Windows; ////// ModelItemDictionary derives from ModelItem and implements support for a /// dictionary of key/value pairs. Both the keys and values are items. /// /// ModelItemDictionary defines an attached property “Key”, which is adds /// to all items contained in the dictionary. The data type of the Key /// property is “ModelItem” and it is marked as non-browsable and /// non-serializable. /// /// In addition to the Key property, ModelItemDictionary also returns an /// Item property from its properties collection just like ModelItemCollection. /// ModelItemDictionary reuses the ModelProperty defined on ModelItemCollection. /// The value returned is an enumeration of the values in the dictionary. /// The Source property of all items in the dictionary refers to this Item /// property. /// public abstract class ModelItemDictionary : ModelItem, IDictionary, IDictionary, INotifyCollectionChanged { /// /// Creates a new ModelItemDictionary. /// protected ModelItemDictionary() { } ////// Returns the item at the given key. Sets the item at the given /// key to the given value. If there is no item for the given key /// this returns null because null is not a valid item. /// /// ////// if key or value is null. ///if the dictionary is read only and you set a new value. ///if the given key is not in the dictionary. [SuppressMessage("Microsoft.Design", "CA1043:UseIntegralOrStringArgumentForIndexers")] public abstract ModelItem this[ModelItem key] { get; set; } ////// Returns the item at the given key. Sets the item at the given /// key to the given value. If there is no item for the given key /// this returns null because null is not a valid item. /// /// ////// if key or value is null. ///if the dictionary is read only and you set a new value. ///if the given key is not in the dictionary. [SuppressMessage("Microsoft.Design", "CA1043:UseIntegralOrStringArgumentForIndexers")] public abstract ModelItem this[object key] { get; set; } ////// Returns the count of items in the dictionary. /// public abstract int Count { get; } ////// Returns true if the dictionary is a fixed size. /// The default implementation returns true if the /// dictionary is read only. /// protected virtual bool IsFixedSize { get { return IsReadOnly; } } ////// Returns true if the dictionary cannot be modified. /// public abstract bool IsReadOnly { get; } ////// Protected access to ICollection.IsSynchronized. /// protected virtual bool IsSynchronized { get { return false; } } ////// Returns the keys of the collection. The keys are guaranteed to be in /// the same order as the values. The resulting collection is read-only. /// [Fx.Tag.KnownXamlExternalAttribute] public abstract ICollectionKeys { get; } /// /// Protected access to the SyncRoot object used to synchronize /// this collection. The default value returns "this". /// protected virtual object SyncRoot { get { return this; } } ////// Returns the values of the collection. The values are guaranteed to be /// in the same order as the keys. The resulting collection is read-only. /// [Fx.Tag.KnownXamlExternalAttribute] public abstract ICollectionValues { get; } /// /// This event is raised when the contents of this collection change. /// public abstract event NotifyCollectionChangedEventHandler CollectionChanged; ////// Adds the item to the dictionary under the given key. /// /// /// ///if key or value is null. ///if the dictionary is read only. public abstract void Add(ModelItem key, ModelItem value); ////// Adds the value to the dictionary under the given key. This /// will wrap the key and value in an item. It returns the item /// representing the key. /// /// /// ///an item representing the key in the dictionary ///if key or value is null. ///if the dictionary is read only. public abstract ModelItem Add(object key, object value); ////// Clears the contents of the dictionary. /// ///if the dictionary is read only. public abstract void Clear(); ////// Copies into the given array. /// /// /// protected virtual void CopyTo(KeyValuePair[] array, int arrayIndex) { foreach (KeyValuePair kv in this) { array[arrayIndex++] = kv; } } /// /// Returns true if the dictionary contains the given key value pair. /// protected virtual bool Contains(KeyValuePairitem) { ModelItem value; return TryGetValue(item.Key, out value) && value == item.Value; } /// /// Returns true if the dictionary contains the given key. /// /// ////// if key is null. public abstract bool ContainsKey(ModelItem key); ////// Returns true if the dictionary contains the given key. /// /// ////// if key is null. public abstract bool ContainsKey(object key); // // Helper method that verifies that objects can be upcast to // the correct type. // private static ModelItem ConvertType(object value) { try { return (ModelItem)value; } catch (InvalidCastException) { throw FxTrace.Exception.AsError(new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.Error_ArgIncorrectType, "value", typeof(ModelItem).FullName))); } } ////// Returns an enumerator for the items in the dictionary. /// ///[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] public abstract IEnumerator > GetEnumerator(); /// /// Removes the item from the dictionary. This does nothing if the item /// does not exist in the collection. /// /// ///if key is null. ///if the dictionary is read only. public abstract bool Remove(ModelItem key); ////// Removes the item from the dictionary. This does nothing if the item /// does not exist in the collection. /// /// ///if key is null. ///if the dictionary is read only. public abstract bool Remove(object key); ////// Retrieves the value for the given key, or returns false if the /// value can’t be found. /// /// /// ////// if key is null. public abstract bool TryGetValue(ModelItem key, out ModelItem value); ////// Retrieves the value for the given key, or returns false if the /// value can’t be found. /// /// /// ////// if key is null. public abstract bool TryGetValue(object key, out ModelItem value); ////// ModelItemDictionary provides an attached property “Key”, which is adds to /// all items contained in the dictionary. The data type of the Key /// property is “ModelItem”. /// public static readonly DependencyProperty KeyProperty = DependencyProperty.RegisterAttachedReadOnly( "Key", typeof(ModelItem), typeof(ModelItemDictionary), null).DependencyProperty; // IDictionary API is synthesized on top of the generic API. #region IDictionary Members ////// IDictionary Implementation maps back to public API. /// void IDictionary.Add(object key, object value) { Add(key, value); } ////// IDictionary Implementation maps back to public API. /// void IDictionary.Clear() { Clear(); } ////// IDictionary Implementation maps back to public API. /// [SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] bool IDictionary.Contains(object key) { return ContainsKey(key); } ////// IDictionary Implementation maps back to public API. /// IDictionaryEnumerator IDictionary.GetEnumerator() { return new DictionaryEnumerator(GetEnumerator()); } ////// IDictionary Implementation maps back to public API. /// bool IDictionary.IsFixedSize { get { return IsFixedSize; } } ////// IDictionary Implementation maps back to public API. /// bool IDictionary.IsReadOnly { get { return IsReadOnly; } } ////// IDictionary Implementation maps back to public API. /// ICollection IDictionary.Keys { get { object[] keys = new object[Count]; int idx = 0; foreach (KeyValuePairkv in this) { keys[idx++] = kv.Key; } return keys; } } /// /// IDictionary Implementation maps back to public API. /// void IDictionary.Remove(object key) { Remove(key); } ////// IDictionary Implementation maps back to public API. /// ICollection IDictionary.Values { get { object[] values = new object[Count]; int idx = 0; foreach (KeyValuePairkv in this) { values[idx++] = kv.Value; } return values; } } /// /// IDictionary Implementation maps back to public API. /// object IDictionary.this[object key] { get { return this[ConvertType(key)]; } set { this[ConvertType(key)] = ConvertType(value); } } #endregion #region ICollection Members ////// ICollection Implementation maps back to public API. /// void ICollection.CopyTo(Array array, int index) { if (Count > 0) { int len = array.GetLength(0); if (index >= len) { throw FxTrace.Exception.AsError(new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.Error_InvalidArrayIndex, index))); } KeyValuePair[] typedArray = new KeyValuePair [len]; CopyTo(typedArray, index); for (; index < typedArray.Length; index++) { array.SetValue(typedArray[index], index); } } } /// /// ICollection Implementation maps back to public API. /// int ICollection.Count { get { return Count; } } ////// ICollection Implementation maps back to public API. /// bool ICollection.IsSynchronized { get { return IsSynchronized; } } ////// ICollection Implementation maps back to public API. /// object ICollection.SyncRoot { get { return SyncRoot; } } #endregion #region IEnumerable Members ////// IEnumerator Implementation maps back to public API. /// IEnumerator IEnumerable.GetEnumerator() { foreach (KeyValuePairkv in this) { yield return kv; } } #endregion #region ICollection > Members void ICollection >.Add(KeyValuePair item) { Add(item.Key, item.Value); } bool ICollection >.Contains(KeyValuePair item) { return Contains(item); } void ICollection >.CopyTo(KeyValuePair [] array, int arrayIndex) { if (arrayIndex >= array.Length) { throw FxTrace.Exception.AsError(new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.Error_InvalidArrayIndex, arrayIndex))); } CopyTo(array, arrayIndex); } bool ICollection >.Remove(KeyValuePair item) { ModelItem value; if (TryGetValue(item.Key, out value) && value == item.Value) { return Remove(item.Key); } return false; } #endregion // // This is a simple struct that implements a dictionary enumerator, // since this isn't supported in the iterator pattern. // private struct DictionaryEnumerator : IDictionaryEnumerator { private IEnumerator > _real; internal DictionaryEnumerator(IEnumerator > real) { _real = real; } #region IDictionaryEnumerator Members public DictionaryEntry Entry { get { return new DictionaryEntry(_real.Current.Key, _real.Current.Value); } } public object Key { get { return _real.Current.Key; } } public object Value { get { return _real.Current.Value; } } #endregion #region IEnumerator Members public object Current { get { return Entry; } } public bool MoveNext() { return _real.MoveNext(); } public void Reset() { _real.Reset(); } #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
- LogicalMethodInfo.cs
- EventRouteFactory.cs
- FontStretches.cs
- XmlAnyElementAttribute.cs
- MetabaseSettingsIis7.cs
- ViewPort3D.cs
- BooleanFunctions.cs
- BitmapCache.cs
- SspiSecurityTokenParameters.cs
- StorageMappingItemCollection.cs
- ComponentSerializationService.cs
- BorderGapMaskConverter.cs
- BamlMapTable.cs
- TagNameToTypeMapper.cs
- ArrayListCollectionBase.cs
- XamlTreeBuilderBamlRecordWriter.cs
- DbProviderManifest.cs
- TreeViewAutomationPeer.cs
- RuntimeCompatibilityAttribute.cs
- LoginCancelEventArgs.cs
- AutomationElement.cs
- EncoderReplacementFallback.cs
- ZoneMembershipCondition.cs
- WebPartEditorOkVerb.cs
- HttpProtocolImporter.cs
- ImageMapEventArgs.cs
- FontWeights.cs
- FaultException.cs
- DetailsView.cs
- ParallelTimeline.cs
- MethodExecutor.cs
- ManagementObjectSearcher.cs
- DataGridViewSelectedColumnCollection.cs
- WinCategoryAttribute.cs
- WebMessageFormatHelper.cs
- MetadataItemEmitter.cs
- TextEffectResolver.cs
- ResetableIterator.cs
- EventBuilder.cs
- DbProviderConfigurationHandler.cs
- IdentityHolder.cs
- CqlErrorHelper.cs
- SqlSelectStatement.cs
- PageTextBox.cs
- DataSourceProvider.cs
- PixelShader.cs
- SqlInfoMessageEvent.cs
- ComponentTray.cs
- OptimalBreakSession.cs
- VoiceChangeEventArgs.cs
- BasicHttpMessageSecurityElement.cs
- WorkingDirectoryEditor.cs
- JapaneseLunisolarCalendar.cs
- ApplicationCommands.cs
- CacheOutputQuery.cs
- ContextMenu.cs
- PasswordPropertyTextAttribute.cs
- Exception.cs
- BrushMappingModeValidation.cs
- EventLog.cs
- DynamicDataResources.Designer.cs
- FtpCachePolicyElement.cs
- XAMLParseException.cs
- SizeLimitedCache.cs
- ExpanderAutomationPeer.cs
- InkCanvas.cs
- XMLUtil.cs
- MessageQueuePermissionEntryCollection.cs
- ControlIdConverter.cs
- UntrustedRecipientException.cs
- ConversionContext.cs
- ItemsControlAutomationPeer.cs
- CodeConstructor.cs
- TextEndOfSegment.cs
- control.ime.cs
- BuildProvidersCompiler.cs
- MimeXmlImporter.cs
- WeakReferenceKey.cs
- XmlExtensionFunction.cs
- DataGridViewComboBoxEditingControl.cs
- FixedDSBuilder.cs
- unsafenativemethodsother.cs
- FixedTextSelectionProcessor.cs
- ServerProtocol.cs
- PageCatalogPart.cs
- FastEncoderWindow.cs
- ZipIOBlockManager.cs
- TextFormatterImp.cs
- ListenerElementsCollection.cs
- EntityContainerEmitter.cs
- ReadOnlyMetadataCollection.cs
- FormatException.cs
- SiteMapDataSource.cs
- ObservableCollection.cs
- SafeLibraryHandle.cs
- DBDataPermissionAttribute.cs
- SchemaMerger.cs
- Helper.cs
- ProfileManager.cs
- XmlDocumentFragment.cs