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
- ControlPager.cs
- TextRangeEditTables.cs
- Soap12ServerProtocol.cs
- FixedStringLookup.cs
- QueryOutputWriter.cs
- TableCellCollection.cs
- DetailsViewRowCollection.cs
- CodeAccessPermission.cs
- ConcurrentBag.cs
- PresentationSource.cs
- PassportAuthentication.cs
- ConvertEvent.cs
- XmlSchemaGroup.cs
- CodeCommentStatementCollection.cs
- BStrWrapper.cs
- AdRotator.cs
- HtmlElementCollection.cs
- XpsFixedPageReaderWriter.cs
- SHA256Managed.cs
- UrlPropertyAttribute.cs
- ConsoleTraceListener.cs
- AppLevelCompilationSectionCache.cs
- CodeLinePragma.cs
- HtmlControl.cs
- ChangeNode.cs
- COMException.cs
- WorkflowInstanceRecord.cs
- DataBoundControlAdapter.cs
- ServiceContractGenerator.cs
- URIFormatException.cs
- ToolStripDropDownClosingEventArgs.cs
- FilterQuery.cs
- Geometry.cs
- ParameterModifier.cs
- XmlAttribute.cs
- ExecutionProperties.cs
- PocoEntityKeyStrategy.cs
- Brushes.cs
- XmlCompatibilityReader.cs
- Scanner.cs
- Fault.cs
- TrustManagerMoreInformation.cs
- LinqTreeNodeEvaluator.cs
- ControlAdapter.cs
- ArrayTypeMismatchException.cs
- Span.cs
- FirstMatchCodeGroup.cs
- Button.cs
- DataViewSetting.cs
- BamlTreeUpdater.cs
- EnvelopedSignatureTransform.cs
- HttpRawResponse.cs
- AppDomainProtocolHandler.cs
- Pen.cs
- AbandonedMutexException.cs
- Freezable.cs
- NamedElement.cs
- TableRowCollection.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- TypedDataSourceCodeGenerator.cs
- TextRangeProviderWrapper.cs
- _ChunkParse.cs
- AppDomainProtocolHandler.cs
- BidOverLoads.cs
- GcHandle.cs
- MethodBuilderInstantiation.cs
- XmlTypeMapping.cs
- FixedSOMImage.cs
- DataGridViewRowConverter.cs
- SqlFactory.cs
- MimeMultiPart.cs
- EmptyEnumerator.cs
- DataSourceControl.cs
- MarkupExtensionParser.cs
- XmlDocumentFragment.cs
- VisualStyleElement.cs
- base64Transforms.cs
- DbConnectionStringBuilder.cs
- ObjectHelper.cs
- ControlDesignerState.cs
- TraceSection.cs
- ImpersonationContext.cs
- BooleanKeyFrameCollection.cs
- MatrixKeyFrameCollection.cs
- SafePEFileHandle.cs
- MemoryResponseElement.cs
- ParseChildrenAsPropertiesAttribute.cs
- ContentFilePart.cs
- LineSegment.cs
- DelegateBodyWriter.cs
- RectAnimationClockResource.cs
- MatrixIndependentAnimationStorage.cs
- DbExpressionBuilder.cs
- UserPersonalizationStateInfo.cs
- Predicate.cs
- UIHelper.cs
- Boolean.cs
- RSATokenProvider.cs
- TemplateBamlRecordReader.cs
- HostVisual.cs