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
- XmlSignificantWhitespace.cs
- XmlSortKeyAccumulator.cs
- RsaEndpointIdentity.cs
- Rect3D.cs
- SafeFileMappingHandle.cs
- DebuggerAttributes.cs
- Sql8ConformanceChecker.cs
- SqlDataSourceCache.cs
- NetworkAddressChange.cs
- XsltLoader.cs
- TextBoxBase.cs
- ResXResourceReader.cs
- SqlConnectionPoolGroupProviderInfo.cs
- ManualResetEvent.cs
- AsyncDataRequest.cs
- QueryLifecycle.cs
- GeometryHitTestParameters.cs
- CannotUnloadAppDomainException.cs
- OverlappedAsyncResult.cs
- InkSerializer.cs
- PropertyValueChangedEvent.cs
- SplitterCancelEvent.cs
- AdornerPresentationContext.cs
- DesignerUtils.cs
- ListViewItemSelectionChangedEvent.cs
- AutomationPropertyInfo.cs
- CodeTypeDelegate.cs
- RtfToken.cs
- RegexParser.cs
- NamespaceInfo.cs
- CounterSample.cs
- OSFeature.cs
- PersonalizationState.cs
- SHA1CryptoServiceProvider.cs
- SourceFileBuildProvider.cs
- SerializationSectionGroup.cs
- FieldBuilder.cs
- DateTimeSerializationSection.cs
- GenericAuthenticationEventArgs.cs
- SystemResourceKey.cs
- DropDownList.cs
- ListViewItem.cs
- XmlAnyElementAttribute.cs
- COM2Properties.cs
- ColorMap.cs
- RichTextBoxAutomationPeer.cs
- ContextProperty.cs
- EditorZoneAutoFormat.cs
- RtfToken.cs
- ServiceMetadataPublishingElement.cs
- Button.cs
- EdmTypeAttribute.cs
- GroupBoxAutomationPeer.cs
- BaseTemplateBuildProvider.cs
- Helper.cs
- DrawingAttributesDefaultValueFactory.cs
- FrameworkContentElement.cs
- ParentQuery.cs
- HMAC.cs
- DescendentsWalker.cs
- COAUTHINFO.cs
- NullableFloatAverageAggregationOperator.cs
- RelAssertionDirectKeyIdentifierClause.cs
- HierarchicalDataSourceIDConverter.cs
- Int64AnimationBase.cs
- TextTreeFixupNode.cs
- Grant.cs
- WindowsRichEdit.cs
- ProxyWebPartManagerDesigner.cs
- BulletedListEventArgs.cs
- ListDictionaryInternal.cs
- securitycriticaldataClass.cs
- XmlChildNodes.cs
- KnownBoxes.cs
- Literal.cs
- XsltOutput.cs
- DataGridCommandEventArgs.cs
- Gdiplus.cs
- StylusPointPropertyInfoDefaults.cs
- NetworkInformationException.cs
- EventEntry.cs
- IFlowDocumentViewer.cs
- SizeF.cs
- Margins.cs
- FilteredSchemaElementLookUpTable.cs
- DataRow.cs
- MessageDesigner.cs
- TrustDriver.cs
- RegistrationServices.cs
- SurrogateEncoder.cs
- SemaphoreSecurity.cs
- CellTreeNodeVisitors.cs
- PersistenceMetadataNamespace.cs
- TextTrailingCharacterEllipsis.cs
- ApplicationSecurityManager.cs
- CodeCatchClauseCollection.cs
- MessagingDescriptionAttribute.cs
- Int16KeyFrameCollection.cs
- ProfileInfo.cs
- Privilege.cs