Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataWeb / Design / system / Data / EntityModel / LazyTextWriterCreator.cs / 2 / 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
- ExtensionQuery.cs
- ProcessManager.cs
- ResourceProperty.cs
- Collection.cs
- BamlTreeNode.cs
- ContextMarshalException.cs
- QilLiteral.cs
- ExpandCollapseProviderWrapper.cs
- UTF8Encoding.cs
- NumericExpr.cs
- PlatformNotSupportedException.cs
- JpegBitmapDecoder.cs
- BeginEvent.cs
- AsyncResult.cs
- X509Extension.cs
- PropertyDescriptorComparer.cs
- ScaleTransform.cs
- XmlObjectSerializerWriteContext.cs
- CacheDependency.cs
- Color.cs
- AnnotationResourceChangedEventArgs.cs
- Compilation.cs
- UIElement3DAutomationPeer.cs
- FontDifferentiator.cs
- ToolboxItemSnapLineBehavior.cs
- CompositeDispatchFormatter.cs
- DynamicUpdateCommand.cs
- Baml2006Reader.cs
- DataServiceRequest.cs
- AnnotationDocumentPaginator.cs
- Transform.cs
- MetadataCollection.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- BoundField.cs
- DependencyPropertyKey.cs
- BrowserCapabilitiesFactoryBase.cs
- CopyOfAction.cs
- RawStylusInputCustomData.cs
- SortQuery.cs
- FamilyTypefaceCollection.cs
- OpCodes.cs
- XPathBuilder.cs
- StrokeCollectionDefaultValueFactory.cs
- SchemaName.cs
- Delay.cs
- BinaryObjectWriter.cs
- CapabilitiesState.cs
- OperationParameterInfo.cs
- RepeaterItemCollection.cs
- NativeMethods.cs
- PathGradientBrush.cs
- DelayedRegex.cs
- FileLoadException.cs
- TaskScheduler.cs
- ExpressionUtilities.cs
- AttachedAnnotation.cs
- XmlSchemaObject.cs
- TextMetrics.cs
- ControlValuePropertyAttribute.cs
- SqlXml.cs
- XmlSchemaValidationException.cs
- GrabHandleGlyph.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- RegionData.cs
- EntityViewGenerationAttribute.cs
- _Semaphore.cs
- SharedHttpTransportManager.cs
- XsltLibrary.cs
- BordersPage.cs
- ForEachAction.cs
- XmlSecureResolver.cs
- Pair.cs
- TextProperties.cs
- PermissionSetEnumerator.cs
- ProviderIncompatibleException.cs
- CultureInfo.cs
- MergablePropertyAttribute.cs
- BoundColumn.cs
- NameValueSectionHandler.cs
- UTF8Encoding.cs
- EditingScope.cs
- BigInt.cs
- StreamGeometry.cs
- EntityType.cs
- HitTestDrawingContextWalker.cs
- QualifiedId.cs
- ResourceDisplayNameAttribute.cs
- PriorityItem.cs
- HandlerFactoryWrapper.cs
- StaticExtension.cs
- Environment.cs
- ZoneMembershipCondition.cs
- XmlKeywords.cs
- FullTrustAssembliesSection.cs
- Listbox.cs
- AnonymousIdentificationModule.cs
- PriorityChain.cs
- BuildDependencySet.cs
- BoolLiteral.cs
- WindowsFormsHostAutomationPeer.cs