Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Common / Utils / DisposableCollectionWrapper.cs / 1305376 / DisposableCollectionWrapper.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace System.Data.Common.Utils { internal class DisposableCollectionWrapper: IDisposable, IEnumerable where T : IDisposable { IEnumerable _enumerable; internal DisposableCollectionWrapper(IEnumerable enumerable) { Debug.Assert(enumerable != null, "don't pass in a null enumerable"); _enumerable = enumerable; } public void Dispose() { // Technically, calling GC.SuppressFinalize is not required because the class does not // have a finalizer, but it does no harm, protects against the case where a finalizer is added // in the future, and prevents an FxCop warning. GC.SuppressFinalize(this); if(_enumerable != null) { foreach(T item in _enumerable) { if(item != null) { item.Dispose(); } } } } public IEnumerator GetEnumerator() { return _enumerable.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return ((System.Collections.IEnumerable)_enumerable).GetEnumerator(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace System.Data.Common.Utils { internal class DisposableCollectionWrapper: IDisposable, IEnumerable where T : IDisposable { IEnumerable _enumerable; internal DisposableCollectionWrapper(IEnumerable enumerable) { Debug.Assert(enumerable != null, "don't pass in a null enumerable"); _enumerable = enumerable; } public void Dispose() { // Technically, calling GC.SuppressFinalize is not required because the class does not // have a finalizer, but it does no harm, protects against the case where a finalizer is added // in the future, and prevents an FxCop warning. GC.SuppressFinalize(this); if(_enumerable != null) { foreach(T item in _enumerable) { if(item != null) { item.Dispose(); } } } } public IEnumerator GetEnumerator() { return _enumerable.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return ((System.Collections.IEnumerable)_enumerable).GetEnumerator(); } } } // 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
- XmlReaderDelegator.cs
- TreeView.cs
- tibetanshape.cs
- Underline.cs
- Enum.cs
- CellConstantDomain.cs
- ScaleTransform.cs
- AsymmetricSignatureFormatter.cs
- ChannelEndpointElement.cs
- SoapMessage.cs
- WebConfigurationHost.cs
- ScriptResourceInfo.cs
- PrintDialogDesigner.cs
- BinaryObjectWriter.cs
- FlowDocumentPage.cs
- AssemblyEvidenceFactory.cs
- OuterGlowBitmapEffect.cs
- SqlBulkCopyColumnMapping.cs
- ContextBase.cs
- AvTraceFormat.cs
- AttributeExtensions.cs
- DrawItemEvent.cs
- AsymmetricKeyExchangeFormatter.cs
- DoubleAnimationBase.cs
- StreamWithDictionary.cs
- SmtpAuthenticationManager.cs
- SecurityElement.cs
- CodeLinePragma.cs
- XmlNamespaceManager.cs
- UIElement.cs
- FaultPropagationQuery.cs
- CallTemplateAction.cs
- WebPartsPersonalizationAuthorization.cs
- StringUtil.cs
- TypeInitializationException.cs
- IndexerNameAttribute.cs
- EpmContentDeSerializerBase.cs
- StackOverflowException.cs
- XsltLoader.cs
- XpsStructure.cs
- SrgsNameValueTag.cs
- MimeMapping.cs
- ApplicationFileParser.cs
- LayoutUtils.cs
- EdmProviderManifest.cs
- ApplicationId.cs
- wgx_render.cs
- PropertyNames.cs
- IntPtr.cs
- DoWorkEventArgs.cs
- DelegatingStream.cs
- HtmlTable.cs
- sqlstateclientmanager.cs
- Timer.cs
- XmlSerializerOperationBehavior.cs
- EventMappingSettingsCollection.cs
- Page.cs
- AmbientProperties.cs
- DecoderNLS.cs
- XmlCountingReader.cs
- AspProxy.cs
- OracleParameterBinding.cs
- OracleString.cs
- LocalizableResourceBuilder.cs
- HostedElements.cs
- RuntimeVariablesExpression.cs
- MapPathBasedVirtualPathProvider.cs
- JsonSerializer.cs
- MimeParameters.cs
- LinkLabelLinkClickedEvent.cs
- LinqDataSourceInsertEventArgs.cs
- SoapAttributes.cs
- VBCodeProvider.cs
- TextEditorDragDrop.cs
- SQLInt32Storage.cs
- ACE.cs
- InputBinder.cs
- CheckBoxPopupAdapter.cs
- FontResourceCache.cs
- ExpressionBindingsDialog.cs
- PenCursorManager.cs
- streamingZipPartStream.cs
- ExpressionVisitor.cs
- AppDomainFactory.cs
- login.cs
- PriorityChain.cs
- ObjectKeyFrameCollection.cs
- Completion.cs
- DocumentGridContextMenu.cs
- GenericAuthenticationEventArgs.cs
- HorizontalAlignConverter.cs
- BooleanFunctions.cs
- _OSSOCK.cs
- DbProviderFactory.cs
- HttpResponse.cs
- IdentityValidationException.cs
- WindowAutomationPeer.cs
- DirectionalLight.cs
- VirtualizingPanel.cs
- PictureBox.cs