Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Design / system / Data / EntityModel / LazyTextWriterCreator.cs / 1305376 / LazyTextWriterCreator.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Diagnostics; using System.IO; namespace System.Data.Services.Design { ////// This class is responsible for abstracting the knowledge /// of whether the user provided a TextWriter or a FilePath. /// /// If the user gave us a filePath we try not to create the TextWriter /// till we absolutely need it in order to prevent the file from being created /// in error cases. /// internal class LazyTextWriterCreator : IDisposable { private bool _ownTextWriter; private TextWriter _writer; private string _targetFilePath; internal LazyTextWriterCreator(string targetFilePath) { Debug.Assert(targetFilePath != null, "targetFilePath parameter is null"); _ownTextWriter = true; _targetFilePath = targetFilePath; } internal LazyTextWriterCreator(TextWriter writer) { _writer = writer; } internal TextWriter GetOrCreateTextWriter() { if (_writer == null) { // lazy creating the writer _writer = new StreamWriter(_targetFilePath); } return _writer; } internal string TargetFilePath { get { return _targetFilePath; } } public void Dispose() { if (_ownTextWriter && _writer != null) { _writer.Dispose(); } GC.SuppressFinalize(this); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Diagnostics; using System.IO; namespace System.Data.Services.Design { ////// This class is responsible for abstracting the knowledge /// of whether the user provided a TextWriter or a FilePath. /// /// If the user gave us a filePath we try not to create the TextWriter /// till we absolutely need it in order to prevent the file from being created /// in error cases. /// internal class LazyTextWriterCreator : IDisposable { private bool _ownTextWriter; private TextWriter _writer; private string _targetFilePath; internal LazyTextWriterCreator(string targetFilePath) { Debug.Assert(targetFilePath != null, "targetFilePath parameter is null"); _ownTextWriter = true; _targetFilePath = targetFilePath; } internal LazyTextWriterCreator(TextWriter writer) { _writer = writer; } internal TextWriter GetOrCreateTextWriter() { if (_writer == null) { // lazy creating the writer _writer = new StreamWriter(_targetFilePath); } return _writer; } internal string TargetFilePath { get { return _targetFilePath; } } public void Dispose() { if (_ownTextWriter && _writer != null) { _writer.Dispose(); } GC.SuppressFinalize(this); } } } // 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
- DataGridViewColumnTypePicker.cs
- DashStyle.cs
- TcpConnectionPool.cs
- XPathArrayIterator.cs
- DataRelation.cs
- FormatterServices.cs
- UserControl.cs
- BitArray.cs
- CodeSnippetStatement.cs
- CompilerWrapper.cs
- KeyInterop.cs
- ResourcePermissionBaseEntry.cs
- XmlCharacterData.cs
- PointCollectionConverter.cs
- XmlFormatMapping.cs
- CompositeClientFormatter.cs
- ServicePoint.cs
- PageParserFilter.cs
- NamespaceQuery.cs
- FontDialog.cs
- GetPageCompletedEventArgs.cs
- DataGridViewTopLeftHeaderCell.cs
- ZipIOLocalFileBlock.cs
- Stream.cs
- MsmqHostedTransportManager.cs
- Part.cs
- AnonymousIdentificationSection.cs
- PropertyMapper.cs
- MediaEntryAttribute.cs
- EpmTargetTree.cs
- ObjectToIdCache.cs
- MetadataCollection.cs
- ManagedIStream.cs
- XmlFormatReaderGenerator.cs
- MachineKeyConverter.cs
- MD5HashHelper.cs
- RectAnimationUsingKeyFrames.cs
- DataRow.cs
- EventProviderWriter.cs
- SessionStateContainer.cs
- BrushMappingModeValidation.cs
- CommandDesigner.cs
- ContextStaticAttribute.cs
- FixedPageStructure.cs
- NextPreviousPagerField.cs
- GridItemPattern.cs
- TextBoxAutomationPeer.cs
- InternalsVisibleToAttribute.cs
- XPathScanner.cs
- DecoderNLS.cs
- Brushes.cs
- VisualStyleInformation.cs
- ResourceIDHelper.cs
- HostingPreferredMapPath.cs
- ErrorFormatter.cs
- TextModifier.cs
- Directory.cs
- WriteFileContext.cs
- TextServicesLoader.cs
- MenuAdapter.cs
- OdbcTransaction.cs
- ResourceContainer.cs
- RawUIStateInputReport.cs
- Size3DConverter.cs
- VolatileEnlistmentState.cs
- SizeFConverter.cs
- Axis.cs
- RadioButtonPopupAdapter.cs
- GridViewColumnCollection.cs
- DataGridViewCellValueEventArgs.cs
- IISMapPath.cs
- RtType.cs
- ArraySortHelper.cs
- TemplateContainer.cs
- ParallelTimeline.cs
- NetworkAddressChange.cs
- XmlElementList.cs
- TableLayoutPanelDesigner.cs
- HtmlInputHidden.cs
- x509store.cs
- RowCache.cs
- SortAction.cs
- StreamSecurityUpgradeAcceptorAsyncResult.cs
- SchemaCollectionCompiler.cs
- IPEndPointCollection.cs
- CustomAttributeFormatException.cs
- QueryHandler.cs
- CharAnimationBase.cs
- ProfileSettings.cs
- DataSourceHelper.cs
- SliderAutomationPeer.cs
- DocumentViewerConstants.cs
- ExpandedWrapper.cs
- MoveSizeWinEventHandler.cs
- PartialList.cs
- Zone.cs
- GridViewCancelEditEventArgs.cs
- HttpErrorTraceRecord.cs
- DataControlField.cs
- Types.cs