Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SoapWriter.cs
- Transform.cs
- MasterPageParser.cs
- TrackingMemoryStreamFactory.cs
- BufferBuilder.cs
- DataObjectPastingEventArgs.cs
- EntitySqlQueryBuilder.cs
- StylusPointProperty.cs
- Keyboard.cs
- EffectiveValueEntry.cs
- Base64Encoder.cs
- Baml2006KeyRecord.cs
- TextElementCollection.cs
- EnumerationRangeValidationUtil.cs
- GenericTypeParameterConverter.cs
- XMLSyntaxException.cs
- HttpApplication.cs
- newitemfactory.cs
- BamlRecords.cs
- DBCommandBuilder.cs
- FontNameConverter.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- Tool.cs
- TogglePattern.cs
- metadatamappinghashervisitor.cs
- XPathBinder.cs
- WebZone.cs
- RoutedCommand.cs
- SpellerStatusTable.cs
- TabPanel.cs
- ConfigurationManagerInternalFactory.cs
- SerializationUtilities.cs
- SqlStream.cs
- AppDomainUnloadedException.cs
- SizeLimitedCache.cs
- DocumentPaginator.cs
- _ConnectStream.cs
- DuplicateWaitObjectException.cs
- LoginDesigner.cs
- DesignerAttribute.cs
- ExpressionBindingCollection.cs
- UIHelper.cs
- CultureMapper.cs
- EnumMember.cs
- DateTimeFormatInfo.cs
- ExpressionList.cs
- ReadWriteObjectLock.cs
- EntryIndex.cs
- BitmapMetadataBlob.cs
- OracleNumber.cs
- ObjectDataSourceFilteringEventArgs.cs
- basenumberconverter.cs
- BufferAllocator.cs
- brushes.cs
- IssuedSecurityTokenParameters.cs
- ListSourceHelper.cs
- XPathNodeInfoAtom.cs
- RichTextBox.cs
- AddInBase.cs
- DataGridColumn.cs
- RenderData.cs
- MobileSysDescriptionAttribute.cs
- CustomValidator.cs
- SoapSchemaMember.cs
- DependencyPropertyHelper.cs
- RtType.cs
- Timer.cs
- UnaryQueryOperator.cs
- AppDomain.cs
- ClickablePoint.cs
- DataGridItem.cs
- RotateTransform3D.cs
- SimpleHandlerFactory.cs
- CollectionViewSource.cs
- FtpCachePolicyElement.cs
- BaseComponentEditor.cs
- Stream.cs
- CanonicalFontFamilyReference.cs
- InputLanguage.cs
- BackoffTimeoutHelper.cs
- ReadWriteSpinLock.cs
- OleDbReferenceCollection.cs
- PageAsyncTaskManager.cs
- MenuItemStyle.cs
- TextTreeRootTextBlock.cs
- DefaultAssemblyResolver.cs
- BitmapEffectDrawingContextState.cs
- Property.cs
- SystemWebCachingSectionGroup.cs
- errorpatternmatcher.cs
- DependencyPropertyKey.cs
- ControlCachePolicy.cs
- FocusChangedEventArgs.cs
- PageAsyncTaskManager.cs
- NamedPipeAppDomainProtocolHandler.cs
- SQLSingleStorage.cs
- OleDbError.cs
- DocumentPageView.cs
- UrlRoutingHandler.cs
- XamlFilter.cs