Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Common / AuthoringOM / ItemList.cs / 1305376 / ItemList.cs
namespace System.Workflow.ComponentModel { using System; using System.Collections; using System.Collections.Generic; [Flags] internal enum ItemListChangeAction { Add = 0x01, Remove = 0x2, Replace = Add | Remove } internal class ItemListChangeEventArgs: EventArgs { private int index = 0; private ICollection addedItems = null; private ICollection removedItems = null; private object owner = null; private ItemListChangeAction action = ItemListChangeAction.Add; public ItemListChangeEventArgs(int index, ICollection removedItems, ICollection addedItems, object owner, ItemListChangeAction action) { this.index = index; this.removedItems = removedItems; this.addedItems = addedItems; this.action = action; this.owner = owner; } public ItemListChangeEventArgs(int index, T removedActivity, T addedActivity, object owner, ItemListChangeAction action) { this.index = index; if ((object)removedActivity != null) { this.removedItems = new List (); ((List )this.removedItems).Add(removedActivity); } if ((object)addedActivity != null) { this.addedItems = new List (); ((List )this.addedItems).Add(addedActivity); } this.action = action; this.owner = owner; } public IList RemovedItems { get { return (this.removedItems != null) ? new List (this.removedItems).AsReadOnly() : new List ().AsReadOnly(); } } public IList AddedItems { get { return (this.addedItems != null) ? new List (this.addedItems).AsReadOnly() : new List ().AsReadOnly(); } } public object Owner { get { return this.owner; } } public int Index { get { return this.index; } } public ItemListChangeAction Action { get { return this.action; } } } internal delegate void ItemListChangeEventHandler (object sender, ItemListChangeEventArgs e); internal class ItemList : List , IList , IList { internal event ItemListChangeEventHandler ListChanging; private object owner = null; internal ItemList(object owner) { this.owner = owner; } protected object Owner { get { return this.owner; } } bool IsFixedSize { get { return false; } } #region ItemList Members public event ItemListChangeEventHandler ListChanged; #endregion #region IList Members void IList .RemoveAt(int index) { if (index < 0 || index > base.Count) throw new ArgumentOutOfRangeException(); T item = base[index]; FireListChanging(new ItemListChangeEventArgs (index, item, default(T), this.owner, ItemListChangeAction.Remove)); base.RemoveAt(index); FireListChanged(new ItemListChangeEventArgs (index, item, default(T), this.owner, ItemListChangeAction.Remove)); } void IList .Insert(int index, T item) { if (index < 0 || index > base.Count) throw new ArgumentOutOfRangeException(); if ((object)item == null) throw new ArgumentNullException("item"); FireListChanging(new ItemListChangeEventArgs (index, default(T), item, this.owner, ItemListChangeAction.Add)); base.Insert(index, item); FireListChanged(new ItemListChangeEventArgs (index, default(T), item, this.owner, ItemListChangeAction.Add)); } T IList .this[int index] { get { return base[index]; } set { if ((object)value == null) throw new ArgumentNullException("item"); T oldItem = base[index]; FireListChanging(new ItemListChangeEventArgs (index, oldItem, value, this.owner, ItemListChangeAction.Replace)); base[index] = value; FireListChanged(new ItemListChangeEventArgs (index, oldItem, value, this.owner, ItemListChangeAction.Replace)); } } int IList .IndexOf(T item) { return base.IndexOf(item); } #endregion #region ICollection Members bool ICollection .IsReadOnly { get { return false; } } bool ICollection .Contains(T item) { return base.Contains(item); } bool ICollection .Remove(T item) { if (!base.Contains(item)) return false; int index = base.IndexOf(item); if (index >= 0) { FireListChanging(new ItemListChangeEventArgs (index, item, default(T), this.owner, ItemListChangeAction.Remove)); base.Remove(item); FireListChanged(new ItemListChangeEventArgs (index, item, default(T), this.owner, ItemListChangeAction.Remove)); return true; } return false; } void ICollection .Clear() { ICollection children = this.GetRange(0, this.Count); FireListChanging(new ItemListChangeEventArgs (-1, children, null, this.owner, ItemListChangeAction.Remove)); base.Clear(); FireListChanged(new ItemListChangeEventArgs (-1, children, null, this.owner, ItemListChangeAction.Remove)); } void ICollection .Add(T item) { if ((object)item == null) throw new ArgumentNullException("item"); FireListChanging(new ItemListChangeEventArgs (base.Count, default(T), item, this.owner, ItemListChangeAction.Add)); base.Add(item); FireListChanged(new ItemListChangeEventArgs (base.Count, default(T), item, this.owner, ItemListChangeAction.Add)); } int ICollection .Count { get { return base.Count; } } void ICollection .CopyTo(T[] array, int arrayIndex) { base.CopyTo(array, arrayIndex); } #endregion #region IEnumerable Members IEnumerator IEnumerable .GetEnumerator() { return base.GetEnumerator(); } #endregion public new void Add(T item) { ((IList )this).Add(item); } public new void AddRange(IEnumerable collection) { if (collection == null) throw new ArgumentNullException("collection"); FireListChanging(new ItemListChangeEventArgs (-1, null, new List (collection), this.owner, ItemListChangeAction.Add)); base.AddRange(collection); FireListChanged(new ItemListChangeEventArgs (base.Count, null, new List (collection), this.owner, ItemListChangeAction.Add)); } public new void InsertRange(int index, IEnumerable collection) { if (index < 0 || index > base.Count) throw new ArgumentOutOfRangeException(); if (collection == null) throw new ArgumentNullException("collection"); FireListChanging(new ItemListChangeEventArgs (index, null, new List (collection), this.owner, ItemListChangeAction.Add)); base.InsertRange(index, collection); FireListChanged(new ItemListChangeEventArgs (index, null, new List (collection), this.owner, ItemListChangeAction.Add)); } public new void Clear() { ((IList )this).Clear(); } public new void Insert(int index, T item) { ((IList )this).Insert(index, item); } public new bool Remove(T item) { return ((IList )this).Remove(item); } public new void RemoveAt(int index) { ((IList )this).RemoveAt(index); } public new T this[int index] { get { return ((IList )this)[index]; } set { ((IList )this)[index] = value; } } #region Helper methods protected virtual void FireListChanging(ItemListChangeEventArgs eventArgs) { if (this.ListChanging != null) this.ListChanging(this, eventArgs); } protected virtual void FireListChanged(ItemListChangeEventArgs eventArgs) { if (this.ListChanged != null) this.ListChanged(this, eventArgs); } #endregion #region IList Members int IList.Add(object value) { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); ((IList )this).Add((T)value); return this.Count - 1; } void IList.Clear() { ((IList )this).Clear(); } bool IList.Contains(object value) { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); return ((IList )this).Contains((T)value); } int IList.IndexOf(object value) { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); return ((IList )this).IndexOf((T)value); } void IList.Insert(int index, object value) { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); ((IList )this).Insert(index, (T)value); } bool IList.IsFixedSize { get { return false; } } bool IList.IsReadOnly { get { return ((IList )this).IsReadOnly; } } void IList.Remove(object value) { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); ((IList )this).Remove((T)value); } object IList.this[int index] { get { return ((IList )this)[index]; } set { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); ((IList )this)[index] = (T)value; } } #endregion #region ICollection Members void ICollection.CopyTo(Array array, int index) { for (int loop = 0; loop < Count; loop++) array.SetValue(this[loop], loop + index); } bool ICollection.IsSynchronized { get { return false; } } object ICollection.SyncRoot { get { return this; } } #endregion #region IEnumerable Members IEnumerator IEnumerable.GetEnumerator() { return base.GetEnumerator(); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Workflow.ComponentModel { using System; using System.Collections; using System.Collections.Generic; [Flags] internal enum ItemListChangeAction { Add = 0x01, Remove = 0x2, Replace = Add | Remove } internal class ItemListChangeEventArgs : EventArgs { private int index = 0; private ICollection addedItems = null; private ICollection removedItems = null; private object owner = null; private ItemListChangeAction action = ItemListChangeAction.Add; public ItemListChangeEventArgs(int index, ICollection removedItems, ICollection addedItems, object owner, ItemListChangeAction action) { this.index = index; this.removedItems = removedItems; this.addedItems = addedItems; this.action = action; this.owner = owner; } public ItemListChangeEventArgs(int index, T removedActivity, T addedActivity, object owner, ItemListChangeAction action) { this.index = index; if ((object)removedActivity != null) { this.removedItems = new List (); ((List )this.removedItems).Add(removedActivity); } if ((object)addedActivity != null) { this.addedItems = new List (); ((List )this.addedItems).Add(addedActivity); } this.action = action; this.owner = owner; } public IList RemovedItems { get { return (this.removedItems != null) ? new List (this.removedItems).AsReadOnly() : new List ().AsReadOnly(); } } public IList AddedItems { get { return (this.addedItems != null) ? new List (this.addedItems).AsReadOnly() : new List ().AsReadOnly(); } } public object Owner { get { return this.owner; } } public int Index { get { return this.index; } } public ItemListChangeAction Action { get { return this.action; } } } internal delegate void ItemListChangeEventHandler (object sender, ItemListChangeEventArgs e); internal class ItemList : List , IList , IList { internal event ItemListChangeEventHandler ListChanging; private object owner = null; internal ItemList(object owner) { this.owner = owner; } protected object Owner { get { return this.owner; } } bool IsFixedSize { get { return false; } } #region ItemList Members public event ItemListChangeEventHandler ListChanged; #endregion #region IList Members void IList .RemoveAt(int index) { if (index < 0 || index > base.Count) throw new ArgumentOutOfRangeException(); T item = base[index]; FireListChanging(new ItemListChangeEventArgs (index, item, default(T), this.owner, ItemListChangeAction.Remove)); base.RemoveAt(index); FireListChanged(new ItemListChangeEventArgs (index, item, default(T), this.owner, ItemListChangeAction.Remove)); } void IList .Insert(int index, T item) { if (index < 0 || index > base.Count) throw new ArgumentOutOfRangeException(); if ((object)item == null) throw new ArgumentNullException("item"); FireListChanging(new ItemListChangeEventArgs (index, default(T), item, this.owner, ItemListChangeAction.Add)); base.Insert(index, item); FireListChanged(new ItemListChangeEventArgs (index, default(T), item, this.owner, ItemListChangeAction.Add)); } T IList .this[int index] { get { return base[index]; } set { if ((object)value == null) throw new ArgumentNullException("item"); T oldItem = base[index]; FireListChanging(new ItemListChangeEventArgs (index, oldItem, value, this.owner, ItemListChangeAction.Replace)); base[index] = value; FireListChanged(new ItemListChangeEventArgs (index, oldItem, value, this.owner, ItemListChangeAction.Replace)); } } int IList .IndexOf(T item) { return base.IndexOf(item); } #endregion #region ICollection Members bool ICollection .IsReadOnly { get { return false; } } bool ICollection .Contains(T item) { return base.Contains(item); } bool ICollection .Remove(T item) { if (!base.Contains(item)) return false; int index = base.IndexOf(item); if (index >= 0) { FireListChanging(new ItemListChangeEventArgs (index, item, default(T), this.owner, ItemListChangeAction.Remove)); base.Remove(item); FireListChanged(new ItemListChangeEventArgs (index, item, default(T), this.owner, ItemListChangeAction.Remove)); return true; } return false; } void ICollection .Clear() { ICollection children = this.GetRange(0, this.Count); FireListChanging(new ItemListChangeEventArgs (-1, children, null, this.owner, ItemListChangeAction.Remove)); base.Clear(); FireListChanged(new ItemListChangeEventArgs (-1, children, null, this.owner, ItemListChangeAction.Remove)); } void ICollection .Add(T item) { if ((object)item == null) throw new ArgumentNullException("item"); FireListChanging(new ItemListChangeEventArgs (base.Count, default(T), item, this.owner, ItemListChangeAction.Add)); base.Add(item); FireListChanged(new ItemListChangeEventArgs (base.Count, default(T), item, this.owner, ItemListChangeAction.Add)); } int ICollection .Count { get { return base.Count; } } void ICollection .CopyTo(T[] array, int arrayIndex) { base.CopyTo(array, arrayIndex); } #endregion #region IEnumerable Members IEnumerator IEnumerable .GetEnumerator() { return base.GetEnumerator(); } #endregion public new void Add(T item) { ((IList )this).Add(item); } public new void AddRange(IEnumerable collection) { if (collection == null) throw new ArgumentNullException("collection"); FireListChanging(new ItemListChangeEventArgs (-1, null, new List (collection), this.owner, ItemListChangeAction.Add)); base.AddRange(collection); FireListChanged(new ItemListChangeEventArgs (base.Count, null, new List (collection), this.owner, ItemListChangeAction.Add)); } public new void InsertRange(int index, IEnumerable collection) { if (index < 0 || index > base.Count) throw new ArgumentOutOfRangeException(); if (collection == null) throw new ArgumentNullException("collection"); FireListChanging(new ItemListChangeEventArgs (index, null, new List (collection), this.owner, ItemListChangeAction.Add)); base.InsertRange(index, collection); FireListChanged(new ItemListChangeEventArgs (index, null, new List (collection), this.owner, ItemListChangeAction.Add)); } public new void Clear() { ((IList )this).Clear(); } public new void Insert(int index, T item) { ((IList )this).Insert(index, item); } public new bool Remove(T item) { return ((IList )this).Remove(item); } public new void RemoveAt(int index) { ((IList )this).RemoveAt(index); } public new T this[int index] { get { return ((IList )this)[index]; } set { ((IList )this)[index] = value; } } #region Helper methods protected virtual void FireListChanging(ItemListChangeEventArgs eventArgs) { if (this.ListChanging != null) this.ListChanging(this, eventArgs); } protected virtual void FireListChanged(ItemListChangeEventArgs eventArgs) { if (this.ListChanged != null) this.ListChanged(this, eventArgs); } #endregion #region IList Members int IList.Add(object value) { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); ((IList )this).Add((T)value); return this.Count - 1; } void IList.Clear() { ((IList )this).Clear(); } bool IList.Contains(object value) { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); return ((IList )this).Contains((T)value); } int IList.IndexOf(object value) { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); return ((IList )this).IndexOf((T)value); } void IList.Insert(int index, object value) { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); ((IList )this).Insert(index, (T)value); } bool IList.IsFixedSize { get { return false; } } bool IList.IsReadOnly { get { return ((IList )this).IsReadOnly; } } void IList.Remove(object value) { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); ((IList )this).Remove((T)value); } object IList.this[int index] { get { return ((IList )this)[index]; } set { if (!(value is T)) throw new Exception(SR.GetString(SR.Error_InvalidListItem, this.GetType().GetGenericArguments()[0].FullName)); ((IList )this)[index] = (T)value; } } #endregion #region ICollection Members void ICollection.CopyTo(Array array, int index) { for (int loop = 0; loop < Count; loop++) array.SetValue(this[loop], loop + index); } bool ICollection.IsSynchronized { get { return false; } } object ICollection.SyncRoot { get { return this; } } #endregion #region IEnumerable Members IEnumerator IEnumerable.GetEnumerator() { return base.GetEnumerator(); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataGridViewRowStateChangedEventArgs.cs
- DriveNotFoundException.cs
- SqlFunctionAttribute.cs
- SqlDataAdapter.cs
- TypeDescriptionProvider.cs
- DataView.cs
- SystemIPAddressInformation.cs
- UserControlAutomationPeer.cs
- SoapMessage.cs
- WebPartDisplayModeEventArgs.cs
- EntityKey.cs
- FunctionUpdateCommand.cs
- IncrementalCompileAnalyzer.cs
- GroupBox.cs
- PipeConnection.cs
- DashStyle.cs
- ScrollItemPattern.cs
- StringBuilder.cs
- SafeHandles.cs
- FontUnitConverter.cs
- MultipleViewPattern.cs
- VirtualizingStackPanel.cs
- ReflectionTypeLoadException.cs
- SrgsRuleRef.cs
- ImageField.cs
- Unit.cs
- ChineseLunisolarCalendar.cs
- ContextMenuStrip.cs
- MeshGeometry3D.cs
- NavigationProperty.cs
- TextRunTypographyProperties.cs
- StorageInfo.cs
- NetworkAddressChange.cs
- DataSourceGeneratorException.cs
- ProcessThreadCollection.cs
- AppSettingsExpressionBuilder.cs
- TrustLevelCollection.cs
- DispatcherOperation.cs
- PresentationUIStyleResources.cs
- StackOverflowException.cs
- Cursor.cs
- Utilities.cs
- ContainerSelectorBehavior.cs
- TextShapeableCharacters.cs
- TypeInformation.cs
- ExpandSegmentCollection.cs
- SR.cs
- GCHandleCookieTable.cs
- GiveFeedbackEvent.cs
- ScrollPattern.cs
- CopyCodeAction.cs
- UrlAuthorizationModule.cs
- WebPartDisplayModeCollection.cs
- ProcessHostMapPath.cs
- BinaryMethodMessage.cs
- NumericUpDownAcceleration.cs
- PropertyGridEditorPart.cs
- FunctionParameter.cs
- SystemUdpStatistics.cs
- StaticSiteMapProvider.cs
- CorrelationInitializer.cs
- EmptyStringExpandableObjectConverter.cs
- UnknownWrapper.cs
- SelectionEditor.cs
- ResolveCompletedEventArgs.cs
- CompilerTypeWithParams.cs
- WmlControlAdapter.cs
- CssClassPropertyAttribute.cs
- ColumnResizeUndoUnit.cs
- EntityExpressionVisitor.cs
- MethodToken.cs
- XPathScanner.cs
- PackageDigitalSignatureManager.cs
- TableItemProviderWrapper.cs
- ColumnHeaderConverter.cs
- GridViewCancelEditEventArgs.cs
- XmlComplianceUtil.cs
- VirtualPathUtility.cs
- RowType.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- DataGridViewComponentPropertyGridSite.cs
- IFlowDocumentViewer.cs
- SecurityManager.cs
- ErrorStyle.cs
- OleDbEnumerator.cs
- EntityRecordInfo.cs
- TrimSurroundingWhitespaceAttribute.cs
- HashRepartitionStream.cs
- IntegrationExceptionEventArgs.cs
- SimpleRecyclingCache.cs
- WindowsAuthenticationEventArgs.cs
- WebControl.cs
- Stack.cs
- ParameterReplacerVisitor.cs
- SeekStoryboard.cs
- BezierSegment.cs
- ChangeTracker.cs
- UserControlDocumentDesigner.cs
- DocumentOrderQuery.cs
- AppDomainFactory.cs