Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- CompositeActivityDesigner.cs
- Logging.cs
- AtlasWeb.Designer.cs
- FamilyMap.cs
- DataGridViewImageColumn.cs
- ContentWrapperAttribute.cs
- TableLayoutPanel.cs
- ShaderEffect.cs
- UserInitiatedNavigationPermission.cs
- LinkConverter.cs
- DataControlFieldCollection.cs
- SortDescription.cs
- DbDataReader.cs
- FillErrorEventArgs.cs
- ExtractedStateEntry.cs
- Helpers.cs
- WsdlParser.cs
- OdbcDataAdapter.cs
- EntityDataSourceConfigureObjectContext.cs
- DiscreteKeyFrames.cs
- TokenFactoryBase.cs
- EntityDataSourceEntitySetNameItem.cs
- FixedPageProcessor.cs
- KeyInstance.cs
- OutKeywords.cs
- ExtensionWindow.cs
- Int32Collection.cs
- Registry.cs
- TraceLevelStore.cs
- ToolStripDropDownClosingEventArgs.cs
- ToolStripItemClickedEventArgs.cs
- NonVisualControlAttribute.cs
- HyperLink.cs
- SmiEventSink.cs
- CompilerErrorCollection.cs
- TouchDevice.cs
- DaylightTime.cs
- WindowsPen.cs
- safesecurityhelperavalon.cs
- DrawingContextWalker.cs
- Color.cs
- SqlStream.cs
- DecoderExceptionFallback.cs
- RowTypePropertyElement.cs
- Stackframe.cs
- DiagnosticTraceSource.cs
- DelayedRegex.cs
- CodeConditionStatement.cs
- PropertyBuilder.cs
- _ScatterGatherBuffers.cs
- PreviewPrintController.cs
- SingleAnimation.cs
- precedingsibling.cs
- DataSourceCacheDurationConverter.cs
- StringStorage.cs
- PropertyTabChangedEvent.cs
- wgx_render.cs
- WebBrowserUriTypeConverter.cs
- ZipIOLocalFileDataDescriptor.cs
- PKCS1MaskGenerationMethod.cs
- AutomationPropertyInfo.cs
- BufferedReadStream.cs
- ScrollBar.cs
- StringArrayConverter.cs
- DataGridTextBoxColumn.cs
- RadialGradientBrush.cs
- SurrogateDataContract.cs
- XmlILConstructAnalyzer.cs
- Identity.cs
- SmiXetterAccessMap.cs
- UnknownExceptionActionHelper.cs
- ExpressionContext.cs
- StyleCollection.cs
- Panel.cs
- CSharpCodeProvider.cs
- WorkflowTransactionOptions.cs
- CompoundFileReference.cs
- GridViewPageEventArgs.cs
- DispatcherHookEventArgs.cs
- StorageAssociationTypeMapping.cs
- WsiProfilesElementCollection.cs
- FixUpCollection.cs
- UserThread.cs
- SizeChangedEventArgs.cs
- Line.cs
- ColorAnimationUsingKeyFrames.cs
- DataViewListener.cs
- PeerNameResolver.cs
- DescendantOverDescendantQuery.cs
- FontUnitConverter.cs
- ListViewGroup.cs
- UnaryNode.cs
- TypeLoadException.cs
- Quad.cs
- _SslSessionsCache.cs
- DbMetaDataColumnNames.cs
- CodeObjectCreateExpression.cs
- TextElementCollection.cs
- DataGridViewColumnTypeEditor.cs
- SerTrace.cs