Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / AddIn / AddIn / System / Addin / Pipeline / ListContractAdapter.cs / 1305376 / ListContractAdapter.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: ListContractAdapter ** ** ===========================================================*/ using System; using System.Collections.Generic; using System.AddIn.Contract; using System.Diagnostics.Contracts; namespace System.AddIn.Pipeline { internal class ListContractAdapter: ContractBase, IListContract { private IList m_list; private Converter m_wrapper; private Converter m_unwrapper; public ListContractAdapter(IList source, Converter wrapper, Converter unwrapper) { if (source == null) throw new ArgumentNullException("source"); if (wrapper == null) throw new ArgumentNullException("wrapper"); if (unwrapper == null) throw new ArgumentNullException("unwrapper"); if (!typeof(U).IsSerializable && !typeof(IContract).IsAssignableFrom(typeof(U))) throw new ArgumentException(Res.TypeShouldBeSerializableOrIContract, typeof(U).Name); System.Diagnostics.Contracts.Contract.EndContractBlock(); m_list = source; m_wrapper = wrapper; m_unwrapper = unwrapper; } public void Add(U item) { m_list.Add(m_unwrapper(item)); } public void Clear() { m_list.Clear(); } public bool Contains(U item) { return m_list.Contains(m_unwrapper(item)); } public int IndexOf(U item) { return m_list.IndexOf(m_unwrapper(item)); } public void Insert(int index, U item) { m_list.Insert(index, m_unwrapper(item)); } public bool Remove(U item) { return m_list.Remove(m_unwrapper(item)); } public void RemoveAt(int index) { m_list.RemoveAt(index); } public U GetItem(int index) { return m_wrapper(m_list[index]); } public void SetItem(int index, U item) { m_list[index] = m_unwrapper(item); } public int GetCount() { return m_list.Count; } public bool GetIsReadOnly() { return m_list.IsReadOnly; } public IEnumeratorContract GetEnumeratorContract() { return new ListEnumeratorAdapter (m_list.GetEnumerator(), m_wrapper); } } internal class ListEnumeratorAdapter : ContractBase, IEnumeratorContract { IEnumerator m_enumerator; Converter m_wrapper; public ListEnumeratorAdapter(IEnumerator enumerator, Converter wrapper) { if (enumerator == null) throw new ArgumentNullException("enumerator"); if (wrapper == null) throw new ArgumentNullException("wrapper"); System.Diagnostics.Contracts.Contract.EndContractBlock(); m_enumerator = enumerator; m_wrapper = wrapper; } public U GetCurrent() { return m_wrapper(m_enumerator.Current); } public bool MoveNext() { return m_enumerator.MoveNext(); } public void Reset() { m_enumerator.Reset(); } public void Dispose() { m_enumerator.Dispose(); } } } // 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
- ListenerTraceUtility.cs
- StringInfo.cs
- EdmProviderManifest.cs
- FunctionParameter.cs
- FileRecordSequenceCompletedAsyncResult.cs
- ListViewSelectEventArgs.cs
- ButtonBase.cs
- Stackframe.cs
- PeerNearMe.cs
- RtfControls.cs
- StreamingContext.cs
- ToolstripProfessionalRenderer.cs
- PolicyDesigner.cs
- DetailsViewDeletedEventArgs.cs
- PathGeometry.cs
- FileDialog_Vista.cs
- ReferenceAssemblyAttribute.cs
- Int64Storage.cs
- UrlParameterWriter.cs
- WebBrowserNavigatedEventHandler.cs
- X509AsymmetricSecurityKey.cs
- GorillaCodec.cs
- RepeaterItemEventArgs.cs
- AnnotationComponentManager.cs
- TracingConnectionListener.cs
- OdbcErrorCollection.cs
- DispatcherSynchronizationContext.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- InheritanceAttribute.cs
- DataGridViewRow.cs
- RawStylusSystemGestureInputReport.cs
- PropertyMetadata.cs
- SHA1Managed.cs
- AsymmetricSignatureDeformatter.cs
- SecurityKeyIdentifierClause.cs
- GrowingArray.cs
- CodeTypeParameter.cs
- UndirectedGraph.cs
- Input.cs
- _FixedSizeReader.cs
- StylusPointPropertyInfoDefaults.cs
- VisualStyleRenderer.cs
- DiagnosticTrace.cs
- ProviderCollection.cs
- MappingItemCollection.cs
- HelpFileFileNameEditor.cs
- OptimizedTemplateContentHelper.cs
- objectresult_tresulttype.cs
- Mapping.cs
- ContextMenuStripActionList.cs
- DocumentationServerProtocol.cs
- PaperSize.cs
- UnwrappedTypesXmlSerializerManager.cs
- SQLGuidStorage.cs
- WindowsSpinner.cs
- ControlIdConverter.cs
- SystemTcpStatistics.cs
- CursorConverter.cs
- ReadOnlyCollectionBuilder.cs
- NativeMethods.cs
- SqlCacheDependency.cs
- QilGeneratorEnv.cs
- BuildManager.cs
- MembershipAdapter.cs
- ReaderWriterLockWrapper.cs
- BaseResourcesBuildProvider.cs
- SqlTransaction.cs
- ToolStripDropDownClosingEventArgs.cs
- _ProxyChain.cs
- FormView.cs
- EmissiveMaterial.cs
- SqlDataSourceConnectionPanel.cs
- OperationParameterInfo.cs
- GridViewSortEventArgs.cs
- CodeAssignStatement.cs
- SequentialUshortCollection.cs
- SafeCloseHandleCritical.cs
- ACE.cs
- SkipQueryOptionExpression.cs
- DataGridViewCellPaintingEventArgs.cs
- PointValueSerializer.cs
- PrintingPermission.cs
- _TimerThread.cs
- EditBehavior.cs
- GroupBoxAutomationPeer.cs
- ComponentEvent.cs
- FieldTemplateUserControl.cs
- ScriptReference.cs
- WebBrowserHelper.cs
- MatrixTransform.cs
- DataGridViewButtonColumn.cs
- HitTestDrawingContextWalker.cs
- FrameworkElement.cs
- HttpMethodConstraint.cs
- ConsoleEntryPoint.cs
- SmtpException.cs
- DataGridCommandEventArgs.cs
- DrawItemEvent.cs
- wpf-etw.cs
- DesignTimeVisibleAttribute.cs