// **************************************************************** // Copyright 2008, Charlie Poole // This is free software licensed under the NUnit license. You may // obtain a copy of the license at http://nunit.org/?p=license&r=2.4 // **************************************************************** using System.IO; namespace NUnit.Core { /// /// Abstract base for classes that capture text output /// and redirect it to a TextWriter. /// public abstract class TextCapture { #region Private Fields /// /// True if capture is enabled /// private bool enabled; /// /// The TextWriter to which text is redirected /// private TextWriter writer; #endregion #region Properties /// /// The TextWriter to which text is redirected /// public TextWriter Writer { get { return writer; } set { writer = value; if (writer != null && enabled) StartCapture(); } } /// /// Controls whether text is captured or not /// public bool Enabled { get { return enabled; } set { if (enabled != value) { if (writer != null && enabled) StopCapture(); enabled = value; if (writer != null && enabled && DefaultThreshold != "Off") StartCapture(); } } } /// /// Returns the default threshold value, which represents /// the degree of verbosity of the output text stream. /// Returns "None" in the base class. Derived classes that /// support verbosity levels should override it. /// public virtual string DefaultThreshold { get { return "None"; } } #endregion #region Abstract Members /// /// Override this to perform whatever actions are needed /// to start capturing text and sending it to the Writer. /// protected abstract void StartCapture(); /// /// Override this to perform whatever actions are needed /// to flush remaining output and stop capturing text. /// The Writer should not be changed, allowing capture /// to be restarted at a future point. /// protected abstract void StopCapture(); #endregion } }