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
- Documentation.cs
- QilTernary.cs
- DataGridBoundColumn.cs
- sqlpipe.cs
- SRef.cs
- RuleSettingsCollection.cs
- Suspend.cs
- AutoResetEvent.cs
- UserNamePasswordValidator.cs
- KoreanCalendar.cs
- StorageAssociationSetMapping.cs
- DataSourceXmlSerializationAttribute.cs
- RouteItem.cs
- DateTimeValueSerializerContext.cs
- TreeViewImageKeyConverter.cs
- SiteMapNodeCollection.cs
- XmlHelper.cs
- SerializationEventsCache.cs
- DynamicObjectAccessor.cs
- LifetimeServices.cs
- CapabilitiesPattern.cs
- DropShadowEffect.cs
- ExeConfigurationFileMap.cs
- CacheDependency.cs
- TypeReference.cs
- Exceptions.cs
- PersonalizableAttribute.cs
- CompilationSection.cs
- SerialErrors.cs
- TemplateGroupCollection.cs
- OutputCacheSection.cs
- ImageConverter.cs
- SecureStringHasher.cs
- ProfileGroupSettingsCollection.cs
- ArcSegment.cs
- TextAdaptor.cs
- HtmlImageAdapter.cs
- WorkflowElementDialog.cs
- ColorInterpolationModeValidation.cs
- SatelliteContractVersionAttribute.cs
- ConfigXmlWhitespace.cs
- GiveFeedbackEvent.cs
- TreeViewBindingsEditorForm.cs
- DrawingContextDrawingContextWalker.cs
- Point4DValueSerializer.cs
- VisualBasicSettings.cs
- CustomActivityDesigner.cs
- SqlInfoMessageEvent.cs
- LoginCancelEventArgs.cs
- RadioButton.cs
- SchemaImporterExtensionElement.cs
- DescendentsWalker.cs
- StringPropertyBuilder.cs
- SlipBehavior.cs
- ForwardPositionQuery.cs
- TypeConverterValueSerializer.cs
- InternalDispatchObject.cs
- CalendarDay.cs
- LineBreak.cs
- DataGridViewEditingControlShowingEventArgs.cs
- DependencyPropertyKey.cs
- WaitHandle.cs
- ImpersonateTokenRef.cs
- IOThreadTimer.cs
- ButtonStandardAdapter.cs
- SafeSecurityHandles.cs
- ProjectionPath.cs
- PageThemeParser.cs
- ScrollPattern.cs
- List.cs
- TrustLevelCollection.cs
- UpdatePanelTrigger.cs
- PhysicalAddress.cs
- TextTreeUndoUnit.cs
- DataGridViewRowEventArgs.cs
- XmlDocument.cs
- SBCSCodePageEncoding.cs
- AmbientLight.cs
- _SslStream.cs
- TimeSpanSecondsConverter.cs
- StreamReader.cs
- CodeAttributeDeclaration.cs
- TextContainerHelper.cs
- AssemblyInfo.cs
- PriorityItem.cs
- RootAction.cs
- ResourcePropertyMemberCodeDomSerializer.cs
- MonthCalendar.cs
- StylusPoint.cs
- ResourceDisplayNameAttribute.cs
- PropertyDescriptorGridEntry.cs
- ValueChangedEventManager.cs
- DeferredSelectedIndexReference.cs
- PropertyTab.cs
- EventHandlersStore.cs
- Stroke.cs
- DataBoundControlAdapter.cs
- CrossContextChannel.cs
- HwndKeyboardInputProvider.cs
- CollectionEditorDialog.cs