Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataWeb / Design / system / Data / EntityModel / LazyTextWriterCreator.cs / 1 / LazyTextWriterCreator.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Diagnostics; 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(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Diagnostics; 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(); } } } } // 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
- CodeCommentStatement.cs
- ValidatingPropertiesEventArgs.cs
- VarInfo.cs
- ListBoxDesigner.cs
- CodeCommentStatementCollection.cs
- SecurityTokenInclusionMode.cs
- PropertyMappingExceptionEventArgs.cs
- SqlVersion.cs
- ExportFileRequest.cs
- FrameworkElementFactory.cs
- OracleMonthSpan.cs
- HttpsHostedTransportConfiguration.cs
- XmlSerializerFactory.cs
- ServiceMemoryGates.cs
- CacheOutputQuery.cs
- InfoCardBinaryReader.cs
- ByteStream.cs
- URLIdentityPermission.cs
- SchemaNamespaceManager.cs
- EnumerableValidator.cs
- IUnknownConstantAttribute.cs
- ExtenderProvidedPropertyAttribute.cs
- XmlCountingReader.cs
- SqlRecordBuffer.cs
- TextWriter.cs
- TextParaClient.cs
- Image.cs
- TreeIterator.cs
- ToolStripDropDownButton.cs
- BaseCAMarshaler.cs
- DebuggerAttributes.cs
- TypeName.cs
- ClientScriptManager.cs
- ReaderContextStackData.cs
- WeakReadOnlyCollection.cs
- TokenCreationException.cs
- GeneralTransform.cs
- BitmapCodecInfoInternal.cs
- MsmqNonTransactedPoisonHandler.cs
- PanelStyle.cs
- PresentationTraceSources.cs
- InfoCardMasterKey.cs
- EventDescriptor.cs
- updateconfighost.cs
- Dump.cs
- DotAtomReader.cs
- TextServicesCompartmentEventSink.cs
- PathData.cs
- RectangleConverter.cs
- SpotLight.cs
- ViewManagerAttribute.cs
- StandardTransformFactory.cs
- MarkupCompiler.cs
- Stroke2.cs
- Point4D.cs
- PropertyManager.cs
- RepeaterDesigner.cs
- PageThemeBuildProvider.cs
- WSHttpBinding.cs
- OletxTransactionHeader.cs
- WebBrowsableAttribute.cs
- DataGridViewTextBoxColumn.cs
- EventLevel.cs
- DelegatingTypeDescriptionProvider.cs
- ApplicationServicesHostFactory.cs
- XmlDictionaryReaderQuotasElement.cs
- InputScope.cs
- DataFieldCollectionEditor.cs
- PropertyPushdownHelper.cs
- PropertyTabChangedEvent.cs
- ParameterReplacerVisitor.cs
- BitVector32.cs
- TemplateBindingExpressionConverter.cs
- ColumnMapTranslator.cs
- SkipStoryboardToFill.cs
- AudioLevelUpdatedEventArgs.cs
- BitmapFrame.cs
- SqlRowUpdatedEvent.cs
- PageContent.cs
- ZipIOFileItemStream.cs
- PeerCustomResolverBindingElement.cs
- ClientScriptManagerWrapper.cs
- SqlAliaser.cs
- Processor.cs
- sqlnorm.cs
- WorkflowRuntimeServiceElement.cs
- TraceLog.cs
- odbcmetadatafactory.cs
- EntityDataSourceDataSelection.cs
- TextTrailingWordEllipsis.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- FocusManager.cs
- ByteFacetDescriptionElement.cs
- Event.cs
- NativeRecognizer.cs
- GridViewCommandEventArgs.cs
- MultiDataTrigger.cs
- ImageBrush.cs
- ExceptionHelpers.cs
- ProviderSettingsCollection.cs