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
- NativeWindow.cs
- PageTextBox.cs
- DelegatingConfigHost.cs
- MediaScriptCommandRoutedEventArgs.cs
- Roles.cs
- EventToken.cs
- GridViewColumnHeader.cs
- InputManager.cs
- AutoGeneratedField.cs
- LogSwitch.cs
- ImageFormatConverter.cs
- ToolboxService.cs
- SqlRowUpdatedEvent.cs
- PartitionedStream.cs
- XmlHelper.cs
- RelationshipWrapper.cs
- Int64Converter.cs
- ProtocolsSection.cs
- InputElement.cs
- MouseEvent.cs
- SystemIPGlobalProperties.cs
- DataTableMappingCollection.cs
- WebReferencesBuildProvider.cs
- CommonDialog.cs
- ResourceContainer.cs
- RemotingHelper.cs
- AssociationSet.cs
- ResourcePermissionBase.cs
- EventArgs.cs
- SafeWaitHandle.cs
- Paragraph.cs
- ContextProperty.cs
- ApplicationDirectoryMembershipCondition.cs
- ExcCanonicalXml.cs
- LockCookie.cs
- IApplicationTrustManager.cs
- DateTimeFormatInfo.cs
- CodePageUtils.cs
- NetworkInterface.cs
- SoapFormatterSinks.cs
- HitTestParameters.cs
- ResourcesBuildProvider.cs
- LazyTextWriterCreator.cs
- MinMaxParagraphWidth.cs
- LinearGradientBrush.cs
- ConfigurationManagerInternal.cs
- WebReferencesBuildProvider.cs
- DataFieldEditor.cs
- GetPageCompletedEventArgs.cs
- CodeIdentifiers.cs
- HttpGetServerProtocol.cs
- ProcessHostConfigUtils.cs
- TemplateXamlParser.cs
- UpdateTranslator.cs
- ClientSponsor.cs
- ColorIndependentAnimationStorage.cs
- RequiredAttributeAttribute.cs
- EntityStoreSchemaGenerator.cs
- BitmapCodecInfoInternal.cs
- Floater.cs
- AnnotationAdorner.cs
- CharacterString.cs
- HelloOperation11AsyncResult.cs
- EmptyEnumerable.cs
- CompiledIdentityConstraint.cs
- DictionaryManager.cs
- DynamicDocumentPaginator.cs
- Expression.cs
- PartEditor.cs
- CompilationLock.cs
- WebPartRestoreVerb.cs
- BaseUriHelper.cs
- BitVector32.cs
- ServiceOperationWrapper.cs
- HandlerBase.cs
- GeneralTransform2DTo3DTo2D.cs
- BamlBinaryReader.cs
- MappingException.cs
- TemplateGroupCollection.cs
- DescendantOverDescendantQuery.cs
- HttpBufferlessInputStream.cs
- Graph.cs
- MediaTimeline.cs
- UInt64Storage.cs
- ImportCatalogPart.cs
- EditingCoordinator.cs
- InputLanguageEventArgs.cs
- NamespaceCollection.cs
- XmlSchemaSimpleContentExtension.cs
- DataSourceXmlElementAttribute.cs
- ConfigXmlReader.cs
- CharacterMetricsDictionary.cs
- NavigationEventArgs.cs
- DragCompletedEventArgs.cs
- HttpSocketManager.cs
- StrongName.cs
- RegexWorker.cs
- WindowShowOrOpenTracker.cs
- BatchParser.cs
- PixelFormatConverter.cs