Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- TemplateXamlTreeBuilder.cs
- HtmlInputRadioButton.cs
- RawKeyboardInputReport.cs
- DesignSurface.cs
- StandardOleMarshalObject.cs
- SessionStateUtil.cs
- Point3DCollectionValueSerializer.cs
- IntSecurity.cs
- CommandConverter.cs
- HMAC.cs
- FormatterServices.cs
- UnionCodeGroup.cs
- ControlHelper.cs
- ScaleTransform3D.cs
- BufferedWebEventProvider.cs
- CustomAttribute.cs
- BaseAsyncResult.cs
- AssociationType.cs
- XmlSchemaType.cs
- FrameworkElementFactory.cs
- TokenFactoryFactory.cs
- BrowserCapabilitiesCodeGenerator.cs
- XmlCollation.cs
- DropTarget.cs
- TextViewElement.cs
- Argument.cs
- ConfigurationStrings.cs
- SqlCacheDependencyDatabase.cs
- CrossAppDomainChannel.cs
- MethodToken.cs
- Matrix3D.cs
- DataTableCollection.cs
- ProtocolsSection.cs
- CacheOutputQuery.cs
- TypeBrowserDialog.cs
- ApplicationHost.cs
- Polygon.cs
- VirtualizingStackPanel.cs
- UInt16Storage.cs
- Point4DValueSerializer.cs
- WindowsEditBoxRange.cs
- AndMessageFilterTable.cs
- EpmSyndicationContentSerializer.cs
- Line.cs
- OracleDataAdapter.cs
- ChangeConflicts.cs
- XamlVector3DCollectionSerializer.cs
- TransactionChannelListener.cs
- ValidationPropertyAttribute.cs
- MimeFormReflector.cs
- DispatcherOperation.cs
- TreeIterator.cs
- Not.cs
- UIElementParaClient.cs
- SmiSettersStream.cs
- BaseTransportHeaders.cs
- XmlAttribute.cs
- DocumentSchemaValidator.cs
- TraceRecords.cs
- PointUtil.cs
- OraclePermission.cs
- FileAuthorizationModule.cs
- COMException.cs
- ButtonChrome.cs
- ResolveDuplex11AsyncResult.cs
- HandlerFactoryWrapper.cs
- SettingsBindableAttribute.cs
- CommandPlan.cs
- HttpRawResponse.cs
- WebScriptEnablingBehavior.cs
- BrowserCapabilitiesCodeGenerator.cs
- ParameterReplacerVisitor.cs
- SafeLocalAllocation.cs
- OdbcConnectionStringbuilder.cs
- ShaderEffect.cs
- PageThemeBuildProvider.cs
- NullReferenceException.cs
- TraceUtils.cs
- DiscoveryEndpoint.cs
- WebPartConnectionsConfigureVerb.cs
- UshortList2.cs
- WebPartDisplayMode.cs
- DataListItemCollection.cs
- RoleService.cs
- PrimarySelectionAdorner.cs
- CodeCompiler.cs
- PlatformCulture.cs
- RuntimeConfig.cs
- CreationContext.cs
- NameSpaceEvent.cs
- FlowDocumentView.cs
- EventRoute.cs
- SystemPens.cs
- HitTestWithPointDrawingContextWalker.cs
- NullableConverter.cs
- BasePropertyDescriptor.cs
- DataError.cs
- Rotation3DAnimationBase.cs
- PropertyEntry.cs
- ToolStripControlHost.cs