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
- UnsafeNativeMethods.cs
- ServiceDurableInstanceContextProvider.cs
- TranslateTransform.cs
- FormViewCommandEventArgs.cs
- DmlSqlGenerator.cs
- CursorConverter.cs
- StatusBar.cs
- RemoteHelper.cs
- WmlFormAdapter.cs
- ImagingCache.cs
- PlainXmlDeserializer.cs
- FormsAuthenticationCredentials.cs
- VarRemapper.cs
- OrderingExpression.cs
- SHA512.cs
- FlowDocumentScrollViewer.cs
- PasswordBoxAutomationPeer.cs
- StyleBamlTreeBuilder.cs
- TabletDevice.cs
- DrawListViewSubItemEventArgs.cs
- KeyedHashAlgorithm.cs
- InputLanguageCollection.cs
- TextModifierScope.cs
- EventMappingSettings.cs
- WinFormsComponentEditor.cs
- ICspAsymmetricAlgorithm.cs
- TextCollapsingProperties.cs
- ResourceIDHelper.cs
- LinkArea.cs
- CapabilitiesState.cs
- HashRepartitionStream.cs
- SamlAdvice.cs
- InkCollectionBehavior.cs
- XmlSignatureManifest.cs
- TextFormatterHost.cs
- PropertyDescriptorCollection.cs
- PropertyDescriptor.cs
- JumpList.cs
- DbConnectionInternal.cs
- PointAnimationUsingPath.cs
- DataGridViewColumnHeaderCell.cs
- XmlIlVisitor.cs
- XmlNodeChangedEventManager.cs
- SmtpMail.cs
- Schedule.cs
- HighlightVisual.cs
- FontNameConverter.cs
- BaseProcessor.cs
- RegisteredExpandoAttribute.cs
- ItemCheckedEvent.cs
- GenericXmlSecurityToken.cs
- DeploymentSection.cs
- DrawingCollection.cs
- HtmlSelect.cs
- PauseStoryboard.cs
- LogEntryHeaderv1Deserializer.cs
- NegotiateStream.cs
- remotingproxy.cs
- QueryNode.cs
- SchemaNames.cs
- Enum.cs
- SettingsPropertyCollection.cs
- ListViewGroupItemCollection.cs
- MachineSettingsSection.cs
- BaseEntityWrapper.cs
- Transform3DGroup.cs
- DocumentOrderComparer.cs
- Symbol.cs
- WebContext.cs
- safemediahandle.cs
- RangeExpression.cs
- IPEndPoint.cs
- ViewEventArgs.cs
- HttpRuntimeSection.cs
- JsonQueryStringConverter.cs
- ParallelEnumerableWrapper.cs
- SvcMapFile.cs
- VisualProxy.cs
- ExpressionParser.cs
- HtmlLiteralTextAdapter.cs
- VariableQuery.cs
- ObjectToIdCache.cs
- OutputScopeManager.cs
- OdbcConnectionHandle.cs
- securestring.cs
- SchemaMapping.cs
- AmbiguousMatchException.cs
- GridEntry.cs
- BaseTypeViewSchema.cs
- AncillaryOps.cs
- WinInetCache.cs
- TileModeValidation.cs
- CultureSpecificStringDictionary.cs
- XmlAtomicValue.cs
- DataObject.cs
- ImageField.cs
- ConfigurationPermission.cs
- Viewport2DVisual3D.cs
- DataGridState.cs
- SuppressIldasmAttribute.cs