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
- ServiceModelConfigurationSection.cs
- ColorKeyFrameCollection.cs
- TreeViewItemAutomationPeer.cs
- CustomPopupPlacement.cs
- DataObjectAttribute.cs
- QueryCreatedEventArgs.cs
- LinkedResource.cs
- LogSwitch.cs
- MergeFilterQuery.cs
- MessageQueueTransaction.cs
- RectangleHotSpot.cs
- CodeParameterDeclarationExpressionCollection.cs
- ContainerParagraph.cs
- EntityCommandCompilationException.cs
- BaseContextMenu.cs
- EventRouteFactory.cs
- mongolianshape.cs
- RetrieveVirtualItemEventArgs.cs
- UserControlCodeDomTreeGenerator.cs
- Path.cs
- InkCollectionBehavior.cs
- ObjectListCommandsPage.cs
- FileDialog.cs
- UpdateException.cs
- CompressionTracing.cs
- RuntimeConfig.cs
- XPathLexer.cs
- InfoCardSymmetricAlgorithm.cs
- EntitySqlQueryBuilder.cs
- OrderedEnumerableRowCollection.cs
- XmlImplementation.cs
- IntSecurity.cs
- BitVec.cs
- PenThreadWorker.cs
- DocumentPageTextView.cs
- TabletDevice.cs
- DockProviderWrapper.cs
- BrowserDefinition.cs
- RawStylusInputReport.cs
- NamespaceDisplay.xaml.cs
- CodeNamespace.cs
- HttpServerUtilityBase.cs
- Win32NamedPipes.cs
- SequenceRange.cs
- ContentAlignmentEditor.cs
- BaseTemplateParser.cs
- ListViewGroupConverter.cs
- Configuration.cs
- Util.cs
- SafeBitVector32.cs
- XmlSchemaNotation.cs
- BoundPropertyEntry.cs
- InspectionWorker.cs
- FilePrompt.cs
- TextEditorParagraphs.cs
- FixedSOMTableRow.cs
- DeclarativeCatalogPart.cs
- DataServiceRequestOfT.cs
- PowerModeChangedEventArgs.cs
- EndPoint.cs
- BlockingCollection.cs
- SqlCacheDependencyDatabaseCollection.cs
- DiscreteKeyFrames.cs
- XNameTypeConverter.cs
- ToolStripContentPanel.cs
- BuildProvidersCompiler.cs
- Byte.cs
- PeerCustomResolverBindingElement.cs
- Message.cs
- CodeStatement.cs
- Track.cs
- XmlWrappingWriter.cs
- DataTableReaderListener.cs
- CodeStatement.cs
- BindingWorker.cs
- EncryptedKeyIdentifierClause.cs
- FileRegion.cs
- EllipticalNodeOperations.cs
- XmlCodeExporter.cs
- EmbeddedObject.cs
- Misc.cs
- BitmapDownload.cs
- ActivityExecutorDelegateInfo.cs
- RelationshipWrapper.cs
- FreezableOperations.cs
- OutputCacheModule.cs
- StrongNameIdentityPermission.cs
- SerializationTrace.cs
- _BufferOffsetSize.cs
- Triplet.cs
- MdiWindowListStrip.cs
- UpdateException.cs
- BamlResourceSerializer.cs
- XmlWhitespace.cs
- FrameworkElementAutomationPeer.cs
- TemplateInstanceAttribute.cs
- Point.cs
- ModuleBuilderData.cs
- ExeContext.cs
- TableCell.cs