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
- VBCodeProvider.cs
- ColorConvertedBitmap.cs
- DataGridViewTextBoxCell.cs
- SectionRecord.cs
- CommonRemoteMemoryBlock.cs
- LineProperties.cs
- ResourceAttributes.cs
- XPathNavigatorReader.cs
- SmiMetaDataProperty.cs
- ExpressionHelper.cs
- DataGridViewHeaderCell.cs
- NotFiniteNumberException.cs
- UIHelper.cs
- NullExtension.cs
- parserscommon.cs
- ForceCopyBuildProvider.cs
- AppDomain.cs
- AddInAttribute.cs
- DataSvcMapFile.cs
- EventLogSession.cs
- ListItem.cs
- ReadonlyMessageFilter.cs
- FixedHighlight.cs
- ObjectContextServiceProvider.cs
- BamlLocalizationDictionary.cs
- RightsManagementEncryptedStream.cs
- PasswordRecoveryAutoFormat.cs
- ApplicationFileCodeDomTreeGenerator.cs
- SqlBulkCopyColumnMappingCollection.cs
- CodeGen.cs
- IPHostEntry.cs
- _IPv4Address.cs
- IsolatedStorage.cs
- indexingfiltermarshaler.cs
- ToolStripSplitStackLayout.cs
- DiagnosticsConfiguration.cs
- ObjectQueryProvider.cs
- ControlBuilderAttribute.cs
- ActivityBuilder.cs
- Polygon.cs
- CompatibleIComparer.cs
- SQLString.cs
- IProvider.cs
- Cursors.cs
- LogEntryHeaderDeserializer.cs
- _HTTPDateParse.cs
- TypeNameHelper.cs
- ChameleonKey.cs
- SchemaElementLookUpTableEnumerator.cs
- ComponentManagerBroker.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- ZipIOModeEnforcingStream.cs
- DataGridItemCollection.cs
- RequestCachePolicy.cs
- MessageSmuggler.cs
- StrokeCollection.cs
- ProgramPublisher.cs
- VirtualDirectoryMapping.cs
- DataRecordObjectView.cs
- TemplateManager.cs
- ImageAttributes.cs
- PerfCounterSection.cs
- GridProviderWrapper.cs
- ToolStripOverflow.cs
- WebHostUnsafeNativeMethods.cs
- ParseChildrenAsPropertiesAttribute.cs
- RoutedEventArgs.cs
- FunctionImportMapping.ReturnTypeRenameMapping.cs
- FixedSOMElement.cs
- SqlBulkCopy.cs
- HtmlLink.cs
- DbConnectionPoolIdentity.cs
- RuleSettings.cs
- IPAddress.cs
- ByteAnimation.cs
- UnsafeNativeMethods.cs
- PrinterUnitConvert.cs
- MessageContractExporter.cs
- GraphicsContainer.cs
- UMPAttributes.cs
- OutKeywords.cs
- TextEvent.cs
- TextTrailingCharacterEllipsis.cs
- ApplicationSettingsBase.cs
- Transform3DGroup.cs
- SystemNetworkInterface.cs
- FileDialog_Vista_Interop.cs
- DataKeyCollection.cs
- DataGridViewRowCancelEventArgs.cs
- UnsafeNativeMethods.cs
- RegexBoyerMoore.cs
- ManagementNamedValueCollection.cs
- SqlXml.cs
- KeyGesture.cs
- SqlCacheDependency.cs
- TableRowCollection.cs
- ConnectionProviderAttribute.cs
- DeploymentExceptionMapper.cs
- TreeNodeBinding.cs
- ClassicBorderDecorator.cs