Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntityDesign / 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.Entity.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 = null; private string _targetFilePath = null; internal LazyTextWriterCreator(TextWriter writer) { Debug.Assert(writer != null, "writer parameter is null"); _ownTextWriter = false; _writer = writer; } internal LazyTextWriterCreator(string targetFilePath) { Debug.Assert(targetFilePath != null, "targetFilePath parameter is null"); _ownTextWriter = true; _targetFilePath = targetFilePath; } 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.Entity.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 = null; private string _targetFilePath = null; internal LazyTextWriterCreator(TextWriter writer) { Debug.Assert(writer != null, "writer parameter is null"); _ownTextWriter = false; _writer = writer; } internal LazyTextWriterCreator(string targetFilePath) { Debug.Assert(targetFilePath != null, "targetFilePath parameter is null"); _ownTextWriter = true; _targetFilePath = targetFilePath; } 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
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- IgnoreFlushAndCloseStream.cs
- ApplicationContext.cs
- UriSection.cs
- PolicyManager.cs
- _SSPIWrapper.cs
- DispatcherProcessingDisabled.cs
- WebMessageEncodingBindingElement.cs
- Point3DAnimation.cs
- NonPrimarySelectionGlyph.cs
- AutomationPropertyInfo.cs
- XmlSchemaSimpleTypeUnion.cs
- AlphaSortedEnumConverter.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- HelpInfo.cs
- CodeAccessSecurityEngine.cs
- _ProxyRegBlob.cs
- DateTimeSerializationSection.cs
- ResourceBinder.cs
- JsonMessageEncoderFactory.cs
- HtmlTextArea.cs
- BitmapEffectRenderDataResource.cs
- UserControlDocumentDesigner.cs
- WebProxyScriptElement.cs
- TableCellCollection.cs
- HttpHandlersSection.cs
- XsltSettings.cs
- StrongBox.cs
- WebBrowserUriTypeConverter.cs
- DynamicValueConverter.cs
- _SSPISessionCache.cs
- AuthorizationSection.cs
- LinearQuaternionKeyFrame.cs
- MimeMapping.cs
- ParenthesizePropertyNameAttribute.cs
- FontEmbeddingManager.cs
- SimpleHandlerFactory.cs
- Pointer.cs
- FontFamilyIdentifier.cs
- SystemKeyConverter.cs
- ThrowHelper.cs
- ArgumentDesigner.xaml.cs
- NonBatchDirectoryCompiler.cs
- AddInController.cs
- NullRuntimeConfig.cs
- TextEffectCollection.cs
- ConstructorBuilder.cs
- CalendarDayButton.cs
- HttpsHostedTransportConfiguration.cs
- ToolboxItem.cs
- RedistVersionInfo.cs
- Wizard.cs
- StringSource.cs
- XmlCountingReader.cs
- SurrogateSelector.cs
- PropertyEmitter.cs
- SoapAttributeOverrides.cs
- FixedSOMContainer.cs
- EditorPartChrome.cs
- SiteMapNodeCollection.cs
- XmlSchemaComplexType.cs
- ThreadInterruptedException.cs
- Tool.cs
- ProfileManager.cs
- WinEventQueueItem.cs
- ScrollPattern.cs
- ConstNode.cs
- NonSerializedAttribute.cs
- ToolStripRenderEventArgs.cs
- ImageAutomationPeer.cs
- CodeNamespaceCollection.cs
- AutoGeneratedField.cs
- StructuredTypeEmitter.cs
- MapPathBasedVirtualPathProvider.cs
- XmlILIndex.cs
- MessageQueuePermission.cs
- VariableAction.cs
- ModelTreeEnumerator.cs
- ToolBarOverflowPanel.cs
- FrameworkReadOnlyPropertyMetadata.cs
- StreamSecurityUpgradeAcceptor.cs
- CodeDirectoryCompiler.cs
- ImageCodecInfoPrivate.cs
- InitializationEventAttribute.cs
- ExpressionEditor.cs
- COM2IProvidePropertyBuilderHandler.cs
- BasicHttpBindingElement.cs
- ClonableStack.cs
- SQLSingle.cs
- ToolStripMenuItem.cs
- GrammarBuilderBase.cs
- FormCollection.cs
- SHA1.cs
- TextEffect.cs
- InvalidOleVariantTypeException.cs
- ResourceReferenceKeyNotFoundException.cs
- LogicalExpr.cs
- loginstatus.cs
- RequestCacheEntry.cs
- MatrixTransform3D.cs
- CryptoConfig.cs