Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntityDesign / 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.Entity.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 = null; private string _targetFilePath = null; internal LazyTextWriterCreator(TextWriter writer) { Debug.Assert(writer != null, "writer parameter is null"); _ownTextWriter = false; _writer = writer; } internal LazyTextWriterCreator(string targetFilePath) { Debug.Assert(targetFilePath != null, "targetFilePath parameter is null"); _ownTextWriter = true; _targetFilePath = targetFilePath; } 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.Entity.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 = null; private string _targetFilePath = null; internal LazyTextWriterCreator(TextWriter writer) { Debug.Assert(writer != null, "writer parameter is null"); _ownTextWriter = false; _writer = writer; } internal LazyTextWriterCreator(string targetFilePath) { Debug.Assert(targetFilePath != null, "targetFilePath parameter is null"); _ownTextWriter = true; _targetFilePath = targetFilePath; } 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
- DeleteCardRequest.cs
- XmlCharacterData.cs
- BitmapEffectDrawingContent.cs
- IMembershipProvider.cs
- ScrollEventArgs.cs
- CellParagraph.cs
- ListViewVirtualItemsSelectionRangeChangedEvent.cs
- ComponentCodeDomSerializer.cs
- ItemPager.cs
- Context.cs
- Bits.cs
- FontWeight.cs
- ObjectSet.cs
- VerificationException.cs
- PasswordBoxAutomationPeer.cs
- NetSectionGroup.cs
- TargetInvocationException.cs
- DataGridViewRowErrorTextNeededEventArgs.cs
- ISessionStateStore.cs
- IfAction.cs
- QueryableFilterRepeater.cs
- DataGridViewCell.cs
- ReachBasicContext.cs
- DescriptionAttribute.cs
- ButtonBaseAutomationPeer.cs
- NullRuntimeConfig.cs
- LogWriteRestartAreaAsyncResult.cs
- SqlClientWrapperSmiStream.cs
- SiteMapPath.cs
- SQLBoolean.cs
- Trace.cs
- PoisonMessageException.cs
- WorkflowRuntimeServicesBehavior.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- MatrixConverter.cs
- Itemizer.cs
- ObjectListSelectEventArgs.cs
- X509IssuerSerialKeyIdentifierClause.cs
- XmlRawWriter.cs
- TreeBuilder.cs
- NumberSubstitution.cs
- BindingRestrictions.cs
- SurrogateEncoder.cs
- BindingExpressionBase.cs
- MailMessageEventArgs.cs
- ObjectHelper.cs
- ExeContext.cs
- RuleElement.cs
- UriExt.cs
- FrameworkTemplate.cs
- StatusBarAutomationPeer.cs
- MenuAdapter.cs
- DocumentGridPage.cs
- URLEditor.cs
- XNodeValidator.cs
- FieldReference.cs
- PathSegment.cs
- MetricEntry.cs
- XmlBindingWorker.cs
- CodeMethodReturnStatement.cs
- DataPagerFieldCollection.cs
- ObjectDisposedException.cs
- ValueQuery.cs
- DataContractFormatAttribute.cs
- WebException.cs
- MenuCommand.cs
- LOSFormatter.cs
- StatusBar.cs
- GridViewDeleteEventArgs.cs
- PeerTransportListenAddressValidator.cs
- arc.cs
- ChannelEndpointElementCollection.cs
- ImplicitInputBrush.cs
- ResourceWriter.cs
- RelationshipConstraintValidator.cs
- StoreItemCollection.cs
- SystemBrushes.cs
- FileReservationCollection.cs
- WhiteSpaceTrimStringConverter.cs
- OperationAbortedException.cs
- TextTreeDeleteContentUndoUnit.cs
- Help.cs
- NotificationContext.cs
- PolyBezierSegmentFigureLogic.cs
- TypeEnumerableViewSchema.cs
- SQLInt16.cs
- WriteableBitmap.cs
- SaveFileDialogDesigner.cs
- ToolboxDataAttribute.cs
- BuildManager.cs
- ManipulationPivot.cs
- RemotingSurrogateSelector.cs
- MessageBox.cs
- SchemaNotation.cs
- PointHitTestResult.cs
- BamlResourceDeserializer.cs
- ControlPropertyNameConverter.cs
- CookieProtection.cs
- GridLength.cs
- SmtpReplyReaderFactory.cs