Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / UI / WebControls / ListItemCollection.cs / 1 / ListItemCollection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System; using System.Collections; using System.ComponentModel; using System.Drawing.Design; using System.Security.Permissions; ////// [ Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)) ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class ListItemCollection : ICollection, IList, IStateManager { private ArrayList listItems; private bool marked; private bool saveAll; ///Encapsulates the items within a ///. /// This class cannot be inherited. /// Initializes a new instance of the /// public ListItemCollection() { listItems = new ArrayList(); marked = false; saveAll = false; } ///class. /// /// public ListItem this[int index] { get { return (ListItem)listItems[index]; } } ///Gets a ///referenced by the specified ordinal /// index value. object IList.this[int index] { get { return listItems[index]; } set { listItems[index] = (ListItem)value; } } public int Capacity { get { return listItems.Capacity; } set { listItems.Capacity = value; } } /// /// public int Count { get { return listItems.Count; } } ///Gets the item count of the collection. ////// public void Add(string item) { Add(new ListItem(item)); } ///Adds the specified item to the end of the collection. ////// public void Add(ListItem item) { listItems.Add(item); if (marked) { item.Dirty = true; } } ///Adds the specified ///to the end of the collection. int IList.Add(object item) { ListItem newItem = (ListItem) item; int returnValue = listItems.Add(newItem); if (marked) { newItem.Dirty = true; } return returnValue; } /// /// public void AddRange(ListItem[] items) { if (items == null) { throw new ArgumentNullException("items"); } foreach(ListItem item in items) { Add(item); } } ////// public void Clear() { listItems.Clear(); if (marked) saveAll = true; } ///Removes all ///controls from the collection. /// public bool Contains(ListItem item) { return listItems.Contains(item); } ///Returns a value indicating whether the /// collection contains the specified item. ///bool IList.Contains(object item) { return Contains((ListItem) item); } /// /// public void CopyTo(Array array, int index) { listItems.CopyTo(array,index); } public ListItem FindByText(string text) { int index = FindByTextInternal(text, true); if (index != -1) { return (ListItem)listItems[index]; } return null; } internal int FindByTextInternal(string text, bool includeDisabled) { int i = 0; foreach (ListItem item in listItems) { if (item.Text.Equals(text) && (includeDisabled || item.Enabled)) { return i; } i++; } return -1; } public ListItem FindByValue(string value) { int index = FindByValueInternal(value, true); if (index != -1) { return (ListItem)listItems[index]; } return null; } internal int FindByValueInternal(string value, bool includeDisabled) { int i = 0; foreach (ListItem item in listItems) { if (item.Value.Equals(value) && (includeDisabled || item.Enabled)) { return i; } i++; } return -1; } ///Copies contents from the collection to a specified ///with a /// specified starting index. /// public IEnumerator GetEnumerator() { return listItems.GetEnumerator(); } ///Returns an enumerator of all ///controls within the /// collection. /// public int IndexOf(ListItem item) { return listItems.IndexOf(item); } ///Returns an ordinal index value that represents the /// position of the specified ///within the collection. int IList.IndexOf(object item) { return IndexOf((ListItem) item); } /// /// public void Insert(int index,string item) { Insert(index,new ListItem(item)); } ///Adds the specified item to the collection at the specified index /// location. ////// public void Insert(int index,ListItem item) { listItems.Insert(index,item); if (marked) saveAll = true; } ///Inserts the specified ///to the collection at the specified /// index location. void IList.Insert(int index, object item) { Insert(index, (ListItem) item); } /// bool IList.IsFixedSize { get { return false; } } /// /// public bool IsReadOnly { get { return listItems.IsReadOnly; } } ///Gets a value indicating whether the collection is read-only. ////// public bool IsSynchronized { get { return listItems.IsSynchronized; } } ///Gets a value indicating whether access to the collection is synchronized /// (thread-safe). ////// public void RemoveAt(int index) { listItems.RemoveAt(index); if (marked) saveAll = true; } ///Removes the ///from the collection at the specified /// index location. /// public void Remove(string item) { int index = IndexOf(new ListItem(item)); if (index >= 0) { RemoveAt(index); } } ///Removes the specified item from the collection. ////// public void Remove(ListItem item) { int index = IndexOf(item); if (index >= 0) { RemoveAt(index); } } ///Removes the specified ///from the collection. void IList.Remove(object item) { Remove((ListItem) item); } /// /// public object SyncRoot { get { return this; } } ///Gets the object that can be used to synchronize access to the collection. In /// this case, it is the collection itself. ////// /// Return true if tracking state changes. /// Method of private interface, IStateManager. /// bool IStateManager.IsTrackingViewState { get { return marked; } } ///void IStateManager.LoadViewState(object state) { LoadViewState(state); } internal void LoadViewState(object state) { if (state != null) { if (state is Pair) { // only changed items were saved Pair p = (Pair) state; ArrayList indices = (ArrayList) p.First; ArrayList items = (ArrayList) p.Second; for (int i=0; i void IStateManager.TrackViewState() { TrackViewState(); } internal void TrackViewState() { marked = true; for (int i=0; i < Count; i++) this[i].TrackViewState(); } /// object IStateManager.SaveViewState() { return SaveViewState(); } internal object SaveViewState() { if (saveAll == true) { // save all items int count = Count; object[] texts = new string[count]; object[] values = new string[count]; bool[] enableds = new bool[count]; for (int i=0; i < count; i++) { texts[i] = this[i].Text; values[i] = this[i].Value; enableds[i] = this[i].Enabled; } return new Triplet(texts, values, enableds); } else { // save only the changed items ArrayList indices = new ArrayList(4); ArrayList items = new ArrayList(4); for (int i=0; i < Count; i++) { object item = this[i].SaveViewState(); if (item != null) { indices.Add(i); items.Add(item); } } if (indices.Count > 0) return new Pair(indices, items); return null; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System; using System.Collections; using System.ComponentModel; using System.Drawing.Design; using System.Security.Permissions; ////// [ Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)) ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class ListItemCollection : ICollection, IList, IStateManager { private ArrayList listItems; private bool marked; private bool saveAll; ///Encapsulates the items within a ///. /// This class cannot be inherited. /// Initializes a new instance of the /// public ListItemCollection() { listItems = new ArrayList(); marked = false; saveAll = false; } ///class. /// /// public ListItem this[int index] { get { return (ListItem)listItems[index]; } } ///Gets a ///referenced by the specified ordinal /// index value. object IList.this[int index] { get { return listItems[index]; } set { listItems[index] = (ListItem)value; } } public int Capacity { get { return listItems.Capacity; } set { listItems.Capacity = value; } } /// /// public int Count { get { return listItems.Count; } } ///Gets the item count of the collection. ////// public void Add(string item) { Add(new ListItem(item)); } ///Adds the specified item to the end of the collection. ////// public void Add(ListItem item) { listItems.Add(item); if (marked) { item.Dirty = true; } } ///Adds the specified ///to the end of the collection. int IList.Add(object item) { ListItem newItem = (ListItem) item; int returnValue = listItems.Add(newItem); if (marked) { newItem.Dirty = true; } return returnValue; } /// /// public void AddRange(ListItem[] items) { if (items == null) { throw new ArgumentNullException("items"); } foreach(ListItem item in items) { Add(item); } } ////// public void Clear() { listItems.Clear(); if (marked) saveAll = true; } ///Removes all ///controls from the collection. /// public bool Contains(ListItem item) { return listItems.Contains(item); } ///Returns a value indicating whether the /// collection contains the specified item. ///bool IList.Contains(object item) { return Contains((ListItem) item); } /// /// public void CopyTo(Array array, int index) { listItems.CopyTo(array,index); } public ListItem FindByText(string text) { int index = FindByTextInternal(text, true); if (index != -1) { return (ListItem)listItems[index]; } return null; } internal int FindByTextInternal(string text, bool includeDisabled) { int i = 0; foreach (ListItem item in listItems) { if (item.Text.Equals(text) && (includeDisabled || item.Enabled)) { return i; } i++; } return -1; } public ListItem FindByValue(string value) { int index = FindByValueInternal(value, true); if (index != -1) { return (ListItem)listItems[index]; } return null; } internal int FindByValueInternal(string value, bool includeDisabled) { int i = 0; foreach (ListItem item in listItems) { if (item.Value.Equals(value) && (includeDisabled || item.Enabled)) { return i; } i++; } return -1; } ///Copies contents from the collection to a specified ///with a /// specified starting index. /// public IEnumerator GetEnumerator() { return listItems.GetEnumerator(); } ///Returns an enumerator of all ///controls within the /// collection. /// public int IndexOf(ListItem item) { return listItems.IndexOf(item); } ///Returns an ordinal index value that represents the /// position of the specified ///within the collection. int IList.IndexOf(object item) { return IndexOf((ListItem) item); } /// /// public void Insert(int index,string item) { Insert(index,new ListItem(item)); } ///Adds the specified item to the collection at the specified index /// location. ////// public void Insert(int index,ListItem item) { listItems.Insert(index,item); if (marked) saveAll = true; } ///Inserts the specified ///to the collection at the specified /// index location. void IList.Insert(int index, object item) { Insert(index, (ListItem) item); } /// bool IList.IsFixedSize { get { return false; } } /// /// public bool IsReadOnly { get { return listItems.IsReadOnly; } } ///Gets a value indicating whether the collection is read-only. ////// public bool IsSynchronized { get { return listItems.IsSynchronized; } } ///Gets a value indicating whether access to the collection is synchronized /// (thread-safe). ////// public void RemoveAt(int index) { listItems.RemoveAt(index); if (marked) saveAll = true; } ///Removes the ///from the collection at the specified /// index location. /// public void Remove(string item) { int index = IndexOf(new ListItem(item)); if (index >= 0) { RemoveAt(index); } } ///Removes the specified item from the collection. ////// public void Remove(ListItem item) { int index = IndexOf(item); if (index >= 0) { RemoveAt(index); } } ///Removes the specified ///from the collection. void IList.Remove(object item) { Remove((ListItem) item); } /// /// public object SyncRoot { get { return this; } } ///Gets the object that can be used to synchronize access to the collection. In /// this case, it is the collection itself. ////// /// Return true if tracking state changes. /// Method of private interface, IStateManager. /// bool IStateManager.IsTrackingViewState { get { return marked; } } ///void IStateManager.LoadViewState(object state) { LoadViewState(state); } internal void LoadViewState(object state) { if (state != null) { if (state is Pair) { // only changed items were saved Pair p = (Pair) state; ArrayList indices = (ArrayList) p.First; ArrayList items = (ArrayList) p.Second; for (int i=0; i void IStateManager.TrackViewState() { TrackViewState(); } internal void TrackViewState() { marked = true; for (int i=0; i < Count; i++) this[i].TrackViewState(); } /// object IStateManager.SaveViewState() { return SaveViewState(); } internal object SaveViewState() { if (saveAll == true) { // save all items int count = Count; object[] texts = new string[count]; object[] values = new string[count]; bool[] enableds = new bool[count]; for (int i=0; i < count; i++) { texts[i] = this[i].Text; values[i] = this[i].Value; enableds[i] = this[i].Enabled; } return new Triplet(texts, values, enableds); } else { // save only the changed items ArrayList indices = new ArrayList(4); ArrayList items = new ArrayList(4); for (int i=0; i < Count; i++) { object item = this[i].SaveViewState(); if (item != null) { indices.Add(i); items.Add(item); } } if (indices.Count > 0) return new Pair(indices, items); return null; } } } } // 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
- SqlMethodAttribute.cs
- SizeAnimationBase.cs
- HtmlShimManager.cs
- ItemChangedEventArgs.cs
- DecoderExceptionFallback.cs
- Rotation3DAnimationUsingKeyFrames.cs
- MessageDecoder.cs
- CompilationRelaxations.cs
- CachedPathData.cs
- ContentPlaceHolder.cs
- AssociationTypeEmitter.cs
- ProjectionPathSegment.cs
- WmfPlaceableFileHeader.cs
- FileCodeGroup.cs
- TargetInvocationException.cs
- BindingMemberInfo.cs
- HtmlImage.cs
- DataListItemCollection.cs
- KeyValuePairs.cs
- HuffmanTree.cs
- FontNameEditor.cs
- DbCommandDefinition.cs
- DetailsViewUpdateEventArgs.cs
- XmlTextReader.cs
- SoapRpcMethodAttribute.cs
- AppLevelCompilationSectionCache.cs
- CompensationParticipant.cs
- ClientBuildManager.cs
- Cursors.cs
- CreateUserWizardStep.cs
- _Semaphore.cs
- XslCompiledTransform.cs
- ConstructorBuilder.cs
- StylusPointPropertyId.cs
- ObjectFullSpanRewriter.cs
- ToolStripMenuItem.cs
- TextReader.cs
- ValidateNames.cs
- HtmlEmptyTagControlBuilder.cs
- EventSourceCreationData.cs
- PermissionSet.cs
- HelpKeywordAttribute.cs
- CombinedGeometry.cs
- DelegateBodyWriter.cs
- SqlParameterizer.cs
- MetadataFile.cs
- ResolveResponse.cs
- ExitEventArgs.cs
- TextElement.cs
- VectorConverter.cs
- FontConverter.cs
- PersistencePipeline.cs
- Span.cs
- ControlOperationInvoker.cs
- Binding.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- QilStrConcat.cs
- Image.cs
- ProtocolElementCollection.cs
- SettingsSection.cs
- webproxy.cs
- WebPartsPersonalization.cs
- SmtpNetworkElement.cs
- HttpResponse.cs
- SpnegoTokenProvider.cs
- DropShadowEffect.cs
- TrustManagerPromptUI.cs
- Parallel.cs
- MenuBindingsEditor.cs
- PropertyTabAttribute.cs
- WindowsStatic.cs
- DependencyPropertyKind.cs
- Util.cs
- EUCJPEncoding.cs
- TransactionBridge.cs
- DataColumnMapping.cs
- DisplayInformation.cs
- ConnectionInterfaceCollection.cs
- ServicePointManagerElement.cs
- UnsafeNativeMethods.cs
- TextElementEditingBehaviorAttribute.cs
- MtomMessageEncoder.cs
- FigureParagraph.cs
- ListSortDescription.cs
- ImageCodecInfoPrivate.cs
- ParserHooks.cs
- EmptyEnumerator.cs
- StoreItemCollection.Loader.cs
- StringInfo.cs
- PermissionSetEnumerator.cs
- UserThread.cs
- Rijndael.cs
- ListView.cs
- HwndSourceParameters.cs
- HttpProfileBase.cs
- ForeignKeyConstraint.cs
- XmlWrappingReader.cs
- DriveNotFoundException.cs
- ExpandableObjectConverter.cs
- RuleValidation.cs