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
- PageThemeParser.cs
- Operator.cs
- SuppressMessageAttribute.cs
- HtmlControlPersistable.cs
- PrintDialog.cs
- SortedList.cs
- Canvas.cs
- RequestContext.cs
- OrderablePartitioner.cs
- CombinedGeometry.cs
- FileSystemEnumerable.cs
- FontFamilyIdentifier.cs
- QueryAccessibilityHelpEvent.cs
- METAHEADER.cs
- ProgressBarHighlightConverter.cs
- WindowsFormsSectionHandler.cs
- OleDbException.cs
- TargetInvocationException.cs
- COAUTHINFO.cs
- base64Transforms.cs
- DoubleLinkListEnumerator.cs
- DefinitionUpdate.cs
- HtmlTableCell.cs
- GACIdentityPermission.cs
- HttpException.cs
- UnionCodeGroup.cs
- ContainerCodeDomSerializer.cs
- InstanceCompleteException.cs
- ObjRef.cs
- BindToObject.cs
- EffectiveValueEntry.cs
- ClientFormsIdentity.cs
- BehaviorService.cs
- WebZoneDesigner.cs
- IApplicationTrustManager.cs
- GeneralTransform3DTo2D.cs
- PartialList.cs
- DurableDispatcherAddressingFault.cs
- EntityProviderFactory.cs
- TaskFactory.cs
- ObjectStorage.cs
- SqlDataSourceQuery.cs
- GridViewAutomationPeer.cs
- XmlDomTextWriter.cs
- AbandonedMutexException.cs
- SchemaImporterExtensionsSection.cs
- SafeSerializationManager.cs
- SqlVisitor.cs
- ServiceParser.cs
- DescendantQuery.cs
- GridViewColumnCollectionChangedEventArgs.cs
- BitmapEffectOutputConnector.cs
- CommandLineParser.cs
- XamlSerializerUtil.cs
- HtmlEncodedRawTextWriter.cs
- IPGlobalProperties.cs
- ApplicationInfo.cs
- XPathNodeIterator.cs
- PackageRelationshipSelector.cs
- StylusPointPropertyUnit.cs
- RightsManagementInformation.cs
- ProfileEventArgs.cs
- DbProviderConfigurationHandler.cs
- HostUtils.cs
- streamingZipPartStream.cs
- Pts.cs
- ErrorRuntimeConfig.cs
- Invariant.cs
- ObjectItemCollection.cs
- CaseInsensitiveOrdinalStringComparer.cs
- CommonRemoteMemoryBlock.cs
- SrgsElementFactoryCompiler.cs
- EnumValidator.cs
- PopupRoot.cs
- ClientBuildManager.cs
- TextSelection.cs
- RelatedView.cs
- ExchangeUtilities.cs
- Camera.cs
- MouseCaptureWithinProperty.cs
- EntityTypeBase.cs
- DataObjectMethodAttribute.cs
- FlowDecision.cs
- DefaultPrintController.cs
- ClientFormsIdentity.cs
- ModulesEntry.cs
- TextBoxDesigner.cs
- IInstanceTable.cs
- HttpRuntimeSection.cs
- InvalidateEvent.cs
- StylusPlugInCollection.cs
- BrowserCapabilitiesFactoryBase.cs
- CardSpaceSelector.cs
- Metadata.cs
- BaseParaClient.cs
- MSAANativeProvider.cs
- ReadOnlyDictionary.cs
- ToolStripDropDownItem.cs
- OleDbReferenceCollection.cs
- IIS7UserPrincipal.cs