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
- SessionPageStateSection.cs
- DynamicObjectAccessor.cs
- UnsafeNativeMethods.cs
- EmbeddedMailObject.cs
- MetabaseServerConfig.cs
- InkCanvasSelectionAdorner.cs
- GridItemPatternIdentifiers.cs
- MdbDataFileEditor.cs
- NewItemsContextMenuStrip.cs
- Executor.cs
- ColorKeyFrameCollection.cs
- SafeNativeMethods.cs
- UpWmlMobileTextWriter.cs
- TextBoxAutoCompleteSourceConverter.cs
- HandleCollector.cs
- EditorPart.cs
- DateTimeOffsetConverter.cs
- RedBlackList.cs
- QilTargetType.cs
- LinkedResource.cs
- PackWebRequestFactory.cs
- WinFormsSecurity.cs
- ExclusiveTcpListener.cs
- ProxyWebPart.cs
- ElementProxy.cs
- URLString.cs
- TextEditorSpelling.cs
- ListItemsPage.cs
- KeyValuePair.cs
- ScanQueryOperator.cs
- MultiViewDesigner.cs
- RouteParser.cs
- OutputCache.cs
- TextRangeSerialization.cs
- ViewStateException.cs
- RijndaelManaged.cs
- HtmlMeta.cs
- EventDescriptor.cs
- AppDomainProtocolHandler.cs
- TreeView.cs
- ObjectDataSourceView.cs
- DeclarationUpdate.cs
- PeerName.cs
- SmiEventSink.cs
- ExponentialEase.cs
- ConfigUtil.cs
- ApplicationTrust.cs
- EntityCollectionChangedParams.cs
- XmlUtilWriter.cs
- Html32TextWriter.cs
- LoginDesigner.cs
- IPAddressCollection.cs
- SiteMapHierarchicalDataSourceView.cs
- WebUtil.cs
- AuthenticationModulesSection.cs
- ListViewUpdateEventArgs.cs
- Timer.cs
- XamlWriterExtensions.cs
- UrlMappingCollection.cs
- ParameterEditorUserControl.cs
- Roles.cs
- CollectionConverter.cs
- WebBrowserSiteBase.cs
- CatalogZone.cs
- EffectiveValueEntry.cs
- OneOf.cs
- MailSettingsSection.cs
- XsdDuration.cs
- _LoggingObject.cs
- WebBrowserHelper.cs
- DrawingCollection.cs
- CreateParams.cs
- ConnectionOrientedTransportChannelFactory.cs
- PageBuildProvider.cs
- DbDataSourceEnumerator.cs
- SQLUtility.cs
- RegexReplacement.cs
- BitConverter.cs
- __Filters.cs
- ButtonRenderer.cs
- WebScriptEnablingBehavior.cs
- PeerNameResolver.cs
- ServiceModelConfigurationSectionCollection.cs
- StringInfo.cs
- Restrictions.cs
- MenuItemStyle.cs
- XLinq.cs
- DefaultBinder.cs
- Int16Storage.cs
- CodeDirectoryCompiler.cs
- Brushes.cs
- XXXOnTypeBuilderInstantiation.cs
- PeerApplicationLaunchInfo.cs
- LinqDataSourceDeleteEventArgs.cs
- ViewGenerator.cs
- SerializationAttributes.cs
- QueryCursorEventArgs.cs
- CheckBox.cs
- RemotingSurrogateSelector.cs
- GridToolTip.cs