Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / XmlUtils / System / Xml / Xsl / ListBase.cs / 1305376 / ListBase.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Xml; using System.Xml.Schema; using System.Collections.Generic; using System.Diagnostics; using System.Text; namespace System.Xml.Xsl { ////// Implementation of read-only IList and IList internal abstract class ListBaseinterfaces. Derived classes can inherit from /// this class and implement only two methods, Count and Item, rather than the entire IList interface. /// : IList , System.Collections.IList { //----------------------------------------------- // Abstract IList methods that must be // implemented by derived classes //----------------------------------------------- public abstract int Count { get; } public abstract T this[int index] { get; set; } //----------------------------------------------- // Implemented by base class -- accessible on // ListBase //----------------------------------------------- public virtual bool Contains(T value) { return IndexOf(value) != -1; } public virtual int IndexOf(T value) { for (int i = 0; i < Count; i++) if (value.Equals(this[i])) return i; return -1; } public virtual void CopyTo(T[] array, int index) { for (int i = 0; i < Count; i++) array[index + i] = this[i]; } public virtual IListEnumerator GetEnumerator() { return new IListEnumerator (this); } public virtual bool IsFixedSize { get { return true; } } public virtual bool IsReadOnly { get { return true; } } public virtual void Add(T value) { Insert(Count, value); } public virtual void Insert(int index, T value) { throw new NotSupportedException(); } public virtual bool Remove(T value) { int index = IndexOf(value); if (index >= 0) { RemoveAt(index); return true; } return false; } public virtual void RemoveAt(int index) { throw new NotSupportedException(); } public virtual void Clear() { for (int index = Count - 1; index >= 0; index--) RemoveAt(index); } //----------------------------------------------- // Implemented by base class -- only accessible // after casting to IList //----------------------------------------------- IEnumerator IEnumerable .GetEnumerator() { return new IListEnumerator (this); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return new IListEnumerator (this); } bool System.Collections.ICollection.IsSynchronized { get { return IsReadOnly; } } object System.Collections.ICollection.SyncRoot { get { return this; } } void System.Collections.ICollection.CopyTo(Array array, int index) { for (int i = 0; i < Count; i++) array.SetValue(this[i], index); } object System.Collections.IList.this[int index] { get { return this[index]; } set { if (!IsCompatibleType(value.GetType())) throw new ArgumentException(Res.GetString(Res.Arg_IncompatibleParamType), "value"); this[index] = (T) value; } } int System.Collections.IList.Add(object value) { if (!IsCompatibleType(value.GetType())) throw new ArgumentException(Res.GetString(Res.Arg_IncompatibleParamType), "value"); Add((T) value); return Count - 1; } void System.Collections.IList.Clear() { Clear(); } bool System.Collections.IList.Contains(object value) { if (!IsCompatibleType(value.GetType())) return false; return Contains((T) value); } int System.Collections.IList.IndexOf(object value) { if (!IsCompatibleType(value.GetType())) return -1; return IndexOf((T) value); } void System.Collections.IList.Insert(int index, object value) { if (!IsCompatibleType(value.GetType())) throw new ArgumentException(Res.GetString(Res.Arg_IncompatibleParamType), "value"); Insert(index, (T) value); } void System.Collections.IList.Remove(object value) { if (IsCompatibleType(value.GetType())) { Remove((T)value); } } //----------------------------------------------- // Helper methods and classes //----------------------------------------------- private static bool IsCompatibleType(object value) { if((value == null && !typeof(T).IsValueType) || (value is T)) return true; return false; } } /// /// Implementation of IEnumerator internal struct IListEnumeratorand IEnumerator over an IList . /// : IEnumerator , System.Collections.IEnumerator { private IList sequence; private int index; private T current; /// /// Constructor. /// public IListEnumerator(IListsequence) { this.sequence = sequence; this.index = 0; this.current = default(T); } /// /// No-op. /// public void Dispose() { } ////// Return current item. Return default value if before first item or after last item in the list. /// public T Current { get { return this.current; } } ////// Return current item. Throw exception if before first item or after last item in the list. /// object System.Collections.IEnumerator.Current { get { if (this.index == 0) throw new InvalidOperationException(Res.GetString(Res.Sch_EnumNotStarted, string.Empty)); if (this.index > this.sequence.Count) throw new InvalidOperationException(Res.GetString(Res.Sch_EnumFinished, string.Empty)); return this.current; } } ////// Advance enumerator to next item in list. Return false if there are no more items. /// public bool MoveNext() { if (this.index < this.sequence.Count) { this.current = this.sequence[this.index]; this.index++; return true; } this.current = default(T); return false; } ////// Set the enumerator to its initial position, which is before the first item in the list. /// void System.Collections.IEnumerator.Reset() { this.index = 0; this.current = default(T); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Xml; using System.Xml.Schema; using System.Collections.Generic; using System.Diagnostics; using System.Text; namespace System.Xml.Xsl { ////// Implementation of read-only IList and IList internal abstract class ListBaseinterfaces. Derived classes can inherit from /// this class and implement only two methods, Count and Item, rather than the entire IList interface. /// : IList , System.Collections.IList { //----------------------------------------------- // Abstract IList methods that must be // implemented by derived classes //----------------------------------------------- public abstract int Count { get; } public abstract T this[int index] { get; set; } //----------------------------------------------- // Implemented by base class -- accessible on // ListBase //----------------------------------------------- public virtual bool Contains(T value) { return IndexOf(value) != -1; } public virtual int IndexOf(T value) { for (int i = 0; i < Count; i++) if (value.Equals(this[i])) return i; return -1; } public virtual void CopyTo(T[] array, int index) { for (int i = 0; i < Count; i++) array[index + i] = this[i]; } public virtual IListEnumerator GetEnumerator() { return new IListEnumerator (this); } public virtual bool IsFixedSize { get { return true; } } public virtual bool IsReadOnly { get { return true; } } public virtual void Add(T value) { Insert(Count, value); } public virtual void Insert(int index, T value) { throw new NotSupportedException(); } public virtual bool Remove(T value) { int index = IndexOf(value); if (index >= 0) { RemoveAt(index); return true; } return false; } public virtual void RemoveAt(int index) { throw new NotSupportedException(); } public virtual void Clear() { for (int index = Count - 1; index >= 0; index--) RemoveAt(index); } //----------------------------------------------- // Implemented by base class -- only accessible // after casting to IList //----------------------------------------------- IEnumerator IEnumerable .GetEnumerator() { return new IListEnumerator (this); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return new IListEnumerator (this); } bool System.Collections.ICollection.IsSynchronized { get { return IsReadOnly; } } object System.Collections.ICollection.SyncRoot { get { return this; } } void System.Collections.ICollection.CopyTo(Array array, int index) { for (int i = 0; i < Count; i++) array.SetValue(this[i], index); } object System.Collections.IList.this[int index] { get { return this[index]; } set { if (!IsCompatibleType(value.GetType())) throw new ArgumentException(Res.GetString(Res.Arg_IncompatibleParamType), "value"); this[index] = (T) value; } } int System.Collections.IList.Add(object value) { if (!IsCompatibleType(value.GetType())) throw new ArgumentException(Res.GetString(Res.Arg_IncompatibleParamType), "value"); Add((T) value); return Count - 1; } void System.Collections.IList.Clear() { Clear(); } bool System.Collections.IList.Contains(object value) { if (!IsCompatibleType(value.GetType())) return false; return Contains((T) value); } int System.Collections.IList.IndexOf(object value) { if (!IsCompatibleType(value.GetType())) return -1; return IndexOf((T) value); } void System.Collections.IList.Insert(int index, object value) { if (!IsCompatibleType(value.GetType())) throw new ArgumentException(Res.GetString(Res.Arg_IncompatibleParamType), "value"); Insert(index, (T) value); } void System.Collections.IList.Remove(object value) { if (IsCompatibleType(value.GetType())) { Remove((T)value); } } //----------------------------------------------- // Helper methods and classes //----------------------------------------------- private static bool IsCompatibleType(object value) { if((value == null && !typeof(T).IsValueType) || (value is T)) return true; return false; } } /// /// Implementation of IEnumerator internal struct IListEnumeratorand IEnumerator over an IList . /// : IEnumerator , System.Collections.IEnumerator { private IList sequence; private int index; private T current; /// /// Constructor. /// public IListEnumerator(IListsequence) { this.sequence = sequence; this.index = 0; this.current = default(T); } /// /// No-op. /// public void Dispose() { } ////// Return current item. Return default value if before first item or after last item in the list. /// public T Current { get { return this.current; } } ////// Return current item. Throw exception if before first item or after last item in the list. /// object System.Collections.IEnumerator.Current { get { if (this.index == 0) throw new InvalidOperationException(Res.GetString(Res.Sch_EnumNotStarted, string.Empty)); if (this.index > this.sequence.Count) throw new InvalidOperationException(Res.GetString(Res.Sch_EnumFinished, string.Empty)); return this.current; } } ////// Advance enumerator to next item in list. Return false if there are no more items. /// public bool MoveNext() { if (this.index < this.sequence.Count) { this.current = this.sequence[this.index]; this.index++; return true; } this.current = default(T); return false; } ////// Set the enumerator to its initial position, which is before the first item in the list. /// void System.Collections.IEnumerator.Reset() { this.index = 0; this.current = default(T); } } } // 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
- LocalFileSettingsProvider.cs
- Sentence.cs
- HitTestResult.cs
- CustomError.cs
- ZipIORawDataFileBlock.cs
- StringSource.cs
- VectorAnimationUsingKeyFrames.cs
- StringCollectionEditor.cs
- AutomationPropertyInfo.cs
- AuthStoreRoleProvider.cs
- FactoryMaker.cs
- ColorBlend.cs
- ThousandthOfEmRealPoints.cs
- BaseParagraph.cs
- EventHandlersStore.cs
- TextureBrush.cs
- CustomTypeDescriptor.cs
- FrameworkReadOnlyPropertyMetadata.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- ArrayConverter.cs
- SharedRuntimeState.cs
- XmlExtensionFunction.cs
- SmtpMail.cs
- EnumerableCollectionView.cs
- GradientStop.cs
- SqlMetaData.cs
- CompatibleIComparer.cs
- ConnectionManagementSection.cs
- ValidationErrorEventArgs.cs
- FixedTextSelectionProcessor.cs
- WebZone.cs
- CallbackHandler.cs
- InfoCardHelper.cs
- BindingsSection.cs
- XmlSignificantWhitespace.cs
- IisTraceListener.cs
- ObjectDataSourceStatusEventArgs.cs
- EditingCoordinator.cs
- MouseEventArgs.cs
- ScaleTransform.cs
- EncoderParameter.cs
- EntityReference.cs
- WebAdminConfigurationHelper.cs
- DataRelation.cs
- FrugalList.cs
- TaskHelper.cs
- OneToOneMappingSerializer.cs
- ServiceSecurityAuditBehavior.cs
- Int32AnimationBase.cs
- DelegatedStream.cs
- SoapHttpTransportImporter.cs
- TextMarkerSource.cs
- SudsCommon.cs
- NavigationWindowAutomationPeer.cs
- WebPartVerbsEventArgs.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- WorkflowDesignerMessageFilter.cs
- InlinedAggregationOperator.cs
- DataKey.cs
- Relationship.cs
- ListViewInsertedEventArgs.cs
- HttpRequest.cs
- SqlDataSourceQueryEditor.cs
- CopyAttributesAction.cs
- BevelBitmapEffect.cs
- ImageSourceTypeConverter.cs
- ProfilePropertySettings.cs
- PostBackOptions.cs
- IntegrationExceptionEventArgs.cs
- Point3DCollectionConverter.cs
- COM2FontConverter.cs
- HwndSource.cs
- InstanceContextManager.cs
- DPAPIProtectedConfigurationProvider.cs
- ComponentManagerBroker.cs
- DesignerForm.cs
- _DigestClient.cs
- ArgumentException.cs
- ViewRendering.cs
- XmlDictionary.cs
- NavigationWindowAutomationPeer.cs
- SafeEventLogWriteHandle.cs
- XmlWriterSettings.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- TokenBasedSet.cs
- AutomationTextAttribute.cs
- ModelPerspective.cs
- ValidationSummaryDesigner.cs
- Operand.cs
- LayoutTableCell.cs
- ServerIdentity.cs
- ClientConfigurationSystem.cs
- Literal.cs
- SqlConnection.cs
- JavaScriptString.cs
- MatrixKeyFrameCollection.cs
- Propagator.JoinPropagator.SubstitutingCloneVisitor.cs
- versioninfo.cs
- ResetableIterator.cs
- WebGetAttribute.cs