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
- ForceCopyBuildProvider.cs
- XmlReflectionMember.cs
- ModelUIElement3D.cs
- Parameter.cs
- SizeAnimationUsingKeyFrames.cs
- TextBox.cs
- StylusPointProperty.cs
- SyntaxCheck.cs
- XmlException.cs
- RelatedEnd.cs
- LinearGradientBrush.cs
- Statements.cs
- WebPartManager.cs
- BamlLocalizableResourceKey.cs
- HttpsHostedTransportConfiguration.cs
- List.cs
- Expressions.cs
- SecureConversationServiceElement.cs
- UpdateEventArgs.cs
- TagPrefixCollection.cs
- WebHttpSecurityModeHelper.cs
- TreeViewTemplateSelector.cs
- DbConnectionPool.cs
- Statements.cs
- RelationshipDetailsRow.cs
- WebUtil.cs
- SystemColors.cs
- ThreadExceptionEvent.cs
- RegexReplacement.cs
- EntityClassGenerator.cs
- BrushMappingModeValidation.cs
- MetadataItemCollectionFactory.cs
- DetailsViewModeEventArgs.cs
- XsdDateTime.cs
- TypedTableHandler.cs
- COAUTHIDENTITY.cs
- NotifyIcon.cs
- QilIterator.cs
- LinkArea.cs
- ResizeGrip.cs
- WindowsFormsHost.cs
- PagerSettings.cs
- MasterPageBuildProvider.cs
- Size3D.cs
- AccessDataSource.cs
- _NestedSingleAsyncResult.cs
- ResourceWriter.cs
- OrderByQueryOptionExpression.cs
- ImageSourceConverter.cs
- FixedFlowMap.cs
- IPAddress.cs
- Polygon.cs
- QueryOutputWriterV1.cs
- DateTimeUtil.cs
- PropertyValueChangedEvent.cs
- MemberHolder.cs
- Point4DConverter.cs
- SchemaSetCompiler.cs
- DiscoveryDocumentSerializer.cs
- AssemblyCache.cs
- Form.cs
- UITypeEditor.cs
- TdsValueSetter.cs
- FontClient.cs
- DesignerDataRelationship.cs
- SurrogateSelector.cs
- CompoundFileIOPermission.cs
- RedirectionProxy.cs
- SqlStatistics.cs
- PasswordTextNavigator.cs
- FixedSOMImage.cs
- StyleHelper.cs
- DataDocumentXPathNavigator.cs
- UnaryExpressionHelper.cs
- XmlSchemaSequence.cs
- SpecularMaterial.cs
- WorkflowMarkupSerializationManager.cs
- BinaryReader.cs
- SpecularMaterial.cs
- ValueType.cs
- KeyConverter.cs
- SoapRpcMethodAttribute.cs
- TypefaceMap.cs
- FrameworkRichTextComposition.cs
- ComponentResourceManager.cs
- UserNameSecurityTokenProvider.cs
- SchemaContext.cs
- GridViewRow.cs
- PerfCounters.cs
- CultureTable.cs
- BulletChrome.cs
- SerialPort.cs
- MexTcpBindingElement.cs
- ClipboardData.cs
- InstallerTypeAttribute.cs
- FamilyTypeface.cs
- XmlObjectSerializer.cs
- AuthenticationServiceManager.cs
- GCHandleCookieTable.cs
- AstTree.cs