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
- SqlCacheDependencySection.cs
- StringDictionary.cs
- ChangesetResponse.cs
- DetailsViewPageEventArgs.cs
- SliderAutomationPeer.cs
- SvcMapFileSerializer.cs
- TypeSystemProvider.cs
- AccessControlEntry.cs
- TextOnlyOutput.cs
- HttpConfigurationContext.cs
- EnumCodeDomSerializer.cs
- DataRecordInfo.cs
- CodeCommentStatement.cs
- OdbcConnectionHandle.cs
- WebPartZoneBase.cs
- RemotingAttributes.cs
- WebCodeGenerator.cs
- GcHandle.cs
- PageContentCollection.cs
- WebPartActionVerb.cs
- WindowsStreamSecurityBindingElement.cs
- CharAnimationUsingKeyFrames.cs
- XmlSignatureProperties.cs
- PolicyLevel.cs
- ClientBuildManager.cs
- PageAdapter.cs
- ReaderWriterLock.cs
- PersistenceTypeAttribute.cs
- _NegoStream.cs
- ResourcesBuildProvider.cs
- InvokePattern.cs
- dsa.cs
- CaseStatementSlot.cs
- ControlDesigner.cs
- WindowVisualStateTracker.cs
- BitmapEffectGroup.cs
- ListViewItemMouseHoverEvent.cs
- Pen.cs
- DateTimeFormatInfoScanner.cs
- EnumConverter.cs
- InputEventArgs.cs
- OfTypeExpression.cs
- XmlCollation.cs
- HttpCacheParams.cs
- XmlQueryRuntime.cs
- TdsParserStaticMethods.cs
- ResourceProviderFactory.cs
- DesignerExtenders.cs
- TdsParserHelperClasses.cs
- DataContractSerializerSection.cs
- formatstringdialog.cs
- CompleteWizardStep.cs
- InputScopeNameConverter.cs
- ReflectionPermission.cs
- WinCategoryAttribute.cs
- X509Certificate2.cs
- SafeNativeMethodsCLR.cs
- PlainXmlSerializer.cs
- ToolStripDropDownItemDesigner.cs
- ObjectHelper.cs
- DesignerTransaction.cs
- ActiveXSite.cs
- WCFServiceClientProxyGenerator.cs
- DataControlFieldCell.cs
- ConfigUtil.cs
- DoubleAnimationClockResource.cs
- SubMenuStyleCollection.cs
- XPathNodeIterator.cs
- ILGenerator.cs
- FontSourceCollection.cs
- XNodeValidator.cs
- StateValidator.cs
- xamlnodes.cs
- XmlWrappingWriter.cs
- ProfileProvider.cs
- TypeName.cs
- InkCanvas.cs
- ADMembershipUser.cs
- CommandDesigner.cs
- contentDescriptor.cs
- RegionIterator.cs
- BaseParser.cs
- SharedPerformanceCounter.cs
- ProxyWebPartManager.cs
- PathSegmentCollection.cs
- ButtonChrome.cs
- DesignerActionUIService.cs
- TypeDelegator.cs
- DataSourceControl.cs
- OperandQuery.cs
- HyperlinkAutomationPeer.cs
- DataView.cs
- DependencySource.cs
- GuidTagList.cs
- WebMessageEncodingBindingElement.cs
- CacheAxisQuery.cs
- FeedUtils.cs
- HttpAsyncResult.cs
- HelpExampleGenerator.cs
- RoutedEvent.cs